Postgresql UUIDs
daniel Tue, 08/02/2011 - 2:54pm
The UUID type.
You don't need to do anything additional to insert/update/read uuids in postgres, but if you want to generate them, you'll need to enable the functions with a script from contrib first:psql -d -U -f /usr/share/postgresql-8.4/contrib/uuid-ossp.sql
Then you can:select uuid_generate_v4();
You should see a uuid in the output.
The functions available via the uuid-ossp module
Other examples of UUID use:
Alter a table to automatically generate uuids:alter table my_table alter column id set default uuid_generate_v4();
Create a table to automatically generate uuids:CREATE TABLE my_table ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY);
- Log in to post comments