UPDATE:
Thanks to @a_horse_with_no_name for pointing out that both question and answer are not relevant as Postgres DOES NOT STORE HYPHENS with the UUID type.
Here is a working solution to achieve something close to what you ask:
CREATE TABLE foo (
ts TIMESTAMP WITH TIME ZONE,
uuid VARCHAR DEFAULT REPLACE(uuid_generate_v4()::text, '-', '' )
);
INSERT INTO foo ( ts ) VALUES ( now() );
BUT (and it is a big but) here we convert uuid
to a string
that means that the index itself will be much more expensive than a number or a real uuid
.
In this article you can find a good explanation:
https://tomharrisonjr.com/uuid-or-guid-as-primary-keys-be-careful-7b2aa3dcb439
As far as I know, Postgres' uuid
uses hyphens even if you try to remove them:
CREATE TABLE foo (
ts TIMESTAMP WITH TIME ZONE,
queue UUID DEFAULT REPLACE(uuid_generate_v4()::text, '-', '' )::uuid,
);
INSERT INTO foo ( ts ) VALUES ( now() );
The example above works just fine in Postgres 9.6, but when we cast back to uuid
hyphens are added back.