I am trying to store UUIDs in a posts table (posts - social media like it doesn't matter), and I would like to know which is the correct way to store UUIDs in PostgreSQL. I have tried to convert them into bytes and store them into binary(16) datatype columns in MySQL. But I cannot find a similar type in PostgreSQL such as binary(16) I found only bytea. So I need a datatype that will help with the size of the column. Is there anything like bytea var-sized?
Asked
Active
Viewed 2,178 times
2
-
There's [`bit(128)`](https://www.postgresql.org/docs/current/datatype-bit.html), but you don't want that. – Bergi Oct 30 '21 at 03:16
-
Is uuid datatype "ok" in terms of storage in comparison with binary? – Monsta Oct 30 '21 at 03:19
-
What do you mean by "ok"? With what `binary` are you comparing it? If you're talking about sqlserver, notice [`binary(16)` shouldn't be used there either](https://dba.stackexchange.com/q/126446/188406). – Bergi Oct 30 '21 at 03:38
-
Yes sorry I was not clear, I meant binary(16) of MySQL I need to find a way to make uuids size lighter – Monsta Oct 30 '21 at 09:10
-
There is no way to make it "lighter". A UUID takes 128 bits or 16 bytes to store, no way around that. (And all of the mentioned data types have this fixed size) – Bergi Oct 30 '21 at 17:39