1 -- regression test for the uuid datatype
2 -- creating test tables
6 text_field TEXT DEFAULT(now())
11 text_field TEXT DEFAULT(now())
13 -- inserting invalid data tests
15 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111F');
16 ERROR: invalid input syntax for uuid: "11111111-1111-1111-1111-111111111111F"
17 LINE 1: INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-111...
20 INSERT INTO guid1(guid_field) VALUES('{11111111-1111-1111-1111-11111111111}');
21 ERROR: invalid input syntax for uuid: "{11111111-1111-1111-1111-11111111111}"
22 LINE 1: INSERT INTO guid1(guid_field) VALUES('{11111111-1111-1111-11...
24 -- valid data but invalid format
25 INSERT INTO guid1(guid_field) VALUES('111-11111-1111-1111-1111-111111111111');
26 ERROR: invalid input syntax for uuid: "111-11111-1111-1111-1111-111111111111"
27 LINE 1: INSERT INTO guid1(guid_field) VALUES('111-11111-1111-1111-11...
29 INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222 ');
30 ERROR: invalid input syntax for uuid: "{22222222-2222-2222-2222-222222222222 "
31 LINE 1: INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-22...
34 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-G111-111111111111');
35 ERROR: invalid input syntax for uuid: "11111111-1111-1111-G111-111111111111"
36 LINE 1: INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-G11...
38 INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-1111-111111111111');
39 ERROR: invalid input syntax for uuid: "11+11111-1111-1111-1111-111111111111"
40 LINE 1: INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-111...
42 --inserting three input formats
43 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
44 INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222}');
45 INSERT INTO guid1(guid_field) VALUES('3f3e3c3b3a3039383736353433a2313e');
46 -- retrieving the inserted data
47 SELECT guid_field FROM guid1;
49 --------------------------------------
50 11111111-1111-1111-1111-111111111111
51 22222222-2222-2222-2222-222222222222
52 3f3e3c3b-3a30-3938-3736-353433a2313e
56 SELECT guid_field FROM guid1 ORDER BY guid_field ASC;
58 --------------------------------------
59 11111111-1111-1111-1111-111111111111
60 22222222-2222-2222-2222-222222222222
61 3f3e3c3b-3a30-3938-3736-353433a2313e
64 SELECT guid_field FROM guid1 ORDER BY guid_field DESC;
66 --------------------------------------
67 3f3e3c3b-3a30-3938-3736-353433a2313e
68 22222222-2222-2222-2222-222222222222
69 11111111-1111-1111-1111-111111111111
73 SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e';
80 SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111';
87 SELECT COUNT(*) FROM guid1 WHERE guid_field < '22222222-2222-2222-2222-222222222222';
94 SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222';
101 SELECT COUNT(*) FROM guid1 WHERE guid_field > '22222222-2222-2222-2222-222222222222';
108 SELECT COUNT(*) FROM guid1 WHERE guid_field >= '22222222-2222-2222-2222-222222222222';
114 -- btree and hash index creation test
115 CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
116 CREATE INDEX guid1_hash ON guid1 USING HASH (guid_field);
118 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
120 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
121 ERROR: duplicate key value violates unique constraint "guid1_unique_btree"
122 -- check to see whether the new indexes are actually there
123 SELECT count(*) FROM pg_class WHERE relkind='i' AND relname LIKE 'guid%';
129 -- populating the test tables with additional records
130 INSERT INTO guid1(guid_field) VALUES('44444444-4444-4444-4444-444444444444');
131 INSERT INTO guid2(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
132 INSERT INTO guid2(guid_field) VALUES('{22222222-2222-2222-2222-222222222222}');
133 INSERT INTO guid2(guid_field) VALUES('3f3e3c3b3a3039383736353433a2313e');
135 SELECT COUNT(*) FROM guid1 g1 INNER JOIN guid2 g2 ON g1.guid_field = g2.guid_field;
141 SELECT COUNT(*) FROM guid1 g1 LEFT JOIN guid2 g2 ON g1.guid_field = g2.guid_field WHERE g2.guid_field IS NULL;
148 DROP TABLE guid1, guid2 CASCADE;