1 set client_min_messages to warning;
4 -- Turn off echo and keep things quiet.
6 -- Format the output for nice TAP.
11 -- Revert all changes on failure.
12 \set ON_ERROR_ROLLBACK 1
13 \set ON_ERROR_STOP true
19 select lives_ok('create temp table uuidtest (id uuid primary key)', 'create temp table');
20 select lives_ok('insert into uuidtest select uuid_v4()', 'generate v4 uuid');
21 select is(uuid_recent(), (select * from uuidtest), 'uuid_recent works');
22 select lives_ok('select uuid_v4()', 'generate v4 uuid');
23 select isnt(uuid_recent(), (select * from uuidtest), 'uuid_recent still works');
25 --Generation Functions:
27 select lives_ok('select uuid_v1()', 'generate v1 uuid');
28 select lives_ok('select uuid_v1mc()', 'generate v1 random mac uuid');
29 select lives_ok(E'select uuid_v3(uuid_recent(), \'llll\'::text)', 'generate v3 uuid');
30 select lives_ok('select uuid_v4()', 'generate v4 uuid');
31 select lives_ok(E'select uuid_v5(uuid_recent(), \'llll\'::text)', 'generate v5 uuid');
32 select lives_ok(E'select uuid_url(\'http://pd.if.org\'::text)', 'generate url uuid');
33 select lives_ok(E'select uuid_dns(\'pd.if.org\'::text)', 'generate url uuid');
34 select lives_ok(E'select uuid_oid(\'2.25\'::text)', 'generate url uuid');
37 --Returns a version 5 uuid using the DNS namespace.
40 select is(uuid_nil(), '00000000-0000-0000-0000-000000000000'::uuid, 'get nil uuid');
41 select is(uuid_ns_dns(), '6ba7b810-9dad-11d1-80b4-00c04fd430c8'::uuid, 'get dns uuid');
42 select is(uuid_ns_url(), '6ba7b811-9dad-11d1-80b4-00c04fd430c8'::uuid, 'get url uuid');
43 select is(uuid_ns_oid(), '6ba7b812-9dad-11d1-80b4-00c04fd430c8'::uuid, 'get oid uuid');
44 select is(uuid_ns_x500(), '6ba7b813-9dad-11d1-80b4-00c04fd430c8'::uuid, 'get x500 uuid');
47 select has_cast('uuid','numeric');
48 select has_cast('uuid','bytea');
49 select has_cast('uuid','bit');
50 select has_cast('uuid','bit varying');
51 select has_cast('numeric', 'uuid');
52 select has_cast('bytea', 'uuid');
53 select has_cast('bit','uuid');
54 select has_cast('bit varying','uuid');
55 select is(uuid_ns_dns()::bytea, '\x6ba7b8109dad11d180b400c04fd430c8'::bytea, 'bytea cast');
56 select is('\x6ba7b8109dad11d180b400c04fd430c8'::bytea::uuid, uuid_ns_dns(), 'bytea uncast');
58 select is(uuid_recent()::numeric::uuid, uuid_recent(), 'reversible numeric cast');
59 select is(uuid_recent()::bytea::uuid, uuid_recent(), 'reversible bytea cast');
60 select is(uuid_recent()::bit(128)::uuid, uuid_recent(), 'reversible bit(128) cast');
61 select is(uuid_recent()::bit varying::uuid, uuid_recent(), 'reversible bit varying cast');
63 -- create a whole bunch of timestamp uuids
64 select lives_ok('insert into uuidtest select uuid_v1() from generate_series(1,10000)', '10000 unique');
66 select * from finish();
71 functions in purepguuid.sql.
73 UUID Lookup Functions:
76 returns the most recent uuid generated by this backend. Returns
77 the nil uuid if no uuids have been generated yet.
79 Numeric: treats the UUID as a 128 bit number and converts it to a numeric.
81 Bit(128) and bit varying: treats the uuid as a 128 bit vector.
82 Casts to bit(n) where n is shorter than 128 will truncate
83 the uuid. Where n is longer than 128, the bit vector
84 will be zero extended.
86 Field extraction functions:
89 Returns an integer corresponding to the 4 bit version number.
92 Returns a macaddr type corresponding to the mac address part of the
93 uuid. This function can be called on any uuid, not just version 1 uuids.
96 Returns a timestamp corresponding to the timestamp field in the uuid. You
97 probably want to use uuid_timestamptz().
99 uuid_timestamptz(uuid)
100 Returns a timestamp with time zonecorresponding to the timestamp field in the