Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MACADDR in Postgres #163

Closed
mehcode opened this issue Mar 26, 2020 · 4 comments · Fixed by #1329
Closed

Support MACADDR in Postgres #163

mehcode opened this issue Mar 26, 2020 · 4 comments · Fixed by #1329
Labels
db:postgres Related to PostgreSQL E-easy enhancement New feature or request good first issue Good for newcomers

Comments

@mehcode
Copy link
Member

mehcode commented Mar 26, 2020

https://docs.rs/mac_address/1.0.3/mac_address/struct.MacAddress.html

@mehcode mehcode added enhancement New feature or request good first issue Good for newcomers db:postgres Related to PostgreSQL E-easy labels Mar 26, 2020
@abonander
Copy link
Collaborator

Type OID: 829
Array type OID: 1040

https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L244-L248

Binary format: i8 i8 i8 i8 i8 i8 (literally just 6 bytes, can pass this straight to MacAddress::new())
https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/mac.c#L161

Use mac_address::MacAddress::from_str to parse the text format.

We can also support the EUI format which is just 8 literal bytes:
https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L260-L264
https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/mac8.c#L295

However, mac_address doesn't support the extended format so we can't do parsing of the text format. Maybe we should just implement our own wrappers instead; it wouldn't be that difficult.

@mehcode
Copy link
Member Author

mehcode commented Mar 31, 2020

https://docs.rs/eui48/0.4.6/eui48/struct.MacAddress.html

This seems to support both kinds.

@abonander
Copy link
Collaborator

The MacAddress type in that crate is still just the 48-bit addresses though.

@EverWinter23
Copy link

From @mehcode on discord:

  • Postgres supports both macaddr and macaddr8 type
  • rust-postgres driver however only supports macaddr type using the eui48 crate
  • eui48 and mac_address crates only support the 6-byte macaddr type

Recommended way-- would be to implement support for macaddr using either eui48 or mac_address (no preference).

If we want to support macaddr8, we should add support for the type to the crate that was used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:postgres Related to PostgreSQL E-easy enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants