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 UUIDs with binary_format=true #260

Open
robsmith11 opened this issue Oct 26, 2022 · 1 comment · May be fixed by #262
Open

Support UUIDs with binary_format=true #260

robsmith11 opened this issue Oct 26, 2022 · 1 comment · May be fixed by #262

Comments

@robsmith11
Copy link

robsmith11 commented Oct 26, 2022

It would be great if UUIDs were interpreted using Julia's UUID type.

This works, but probably not the mot efficient way:

postgres=# create table t (x uuid);
CREATE TABLE
postgres=# insert into t values(uuid_in(md5(random()::text || random()::text)::cstring));
INSERT 0 1
postgres=# insert into t values(uuid_in(md5(random()::text || random()::text)::cstring));
INSERT 0 1
postgres=# insert into t values(uuid_in(md5(random()::text || random()::text)::cstring));
INSERT 0 1
postgres=# select * from t;
                  x
--------------------------------------
 b8445ef2-ed8e-b4dd-c5da-c5097155a45c
 ed7676b9-f78f-c2f1-84d5-a6267485cd4a
 77ca6bf5-7621-bc8a-034c-1a853a97b516
julia> t = LibPQ.execute(c, "select * from t", binary_format=true, not_null=true) |> Tables.columntable
(x = ["\xb8D^\xf2펴\xdd\xc5\xda\xc5\tqU\xa4\\", "\xedvv\xb9\xf7\x8f\xc2\xf1\x84զ&t\x85\xcdJ", "w\xcak\xf5v!\xbc\x8a\x03L\x1a\x85:\x97\xb5\x16"],)

julia> [reinterpret(UUIDs.UUID, reverse(Vector{UInt8}(x)))[1] for x in t.x]
3-element Vector{Base.UUID}:
 UUID("b8445ef2-ed8e-b4dd-c5da-c5097155a45c")
 UUID("ed7676b9-f78f-c2f1-84d5-a6267485cd4a")
 UUID("77ca6bf5-7621-bc8a-034c-1a853a97b516")
@iamed2
Copy link
Collaborator

iamed2 commented Oct 27, 2022

Thanks for this example, that's a great reference for implementation!

@iamed2 iamed2 linked a pull request Oct 27, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants