]> granicus.if.org Git - postgresql/blob - contrib/lo/lo_test.sql
Cleanup the contrib/lo module: there is no need anymore to implement
[postgresql] / contrib / lo / lo_test.sql
1 --
2 -- This runs some common tests against the type
3 --
4 -- It's used just for development
5 --
6 -- XXX would be nice to turn this into a proper regression test
7 --
8
9 -- Check what is in pg_largeobject
10 SELECT count(DISTINCT loid) FROM pg_largeobject;
11
12 -- ignore any errors here - simply drop the table if it already exists
13 DROP TABLE a;
14
15 -- create the test table
16 CREATE TABLE a (fname name,image lo);
17
18 -- insert a null object
19 INSERT INTO a VALUES ('empty');
20
21 -- insert a large object based on a file
22 INSERT INTO a VALUES ('/etc/group', lo_import('/etc/group')::lo);
23
24 -- now select the table
25 SELECT * FROM a;
26
27 -- check that coercion to plain oid works
28 SELECT *,image::oid from a;
29
30 -- now test the trigger
31 CREATE TRIGGER t_a
32 BEFORE UPDATE OR DELETE ON a
33 FOR EACH ROW
34 EXECUTE PROCEDURE lo_manage(image);
35
36 -- insert
37 INSERT INTO a VALUES ('aa', lo_import('/etc/hosts'));
38 SELECT * FROM a
39 WHERE fname LIKE 'aa%';
40
41 -- update
42 UPDATE a SET image=lo_import('/etc/group')::lo
43 WHERE fname='aa';
44 SELECT * FROM a
45 WHERE fname LIKE 'aa%';
46
47 -- update the 'empty' row which should be null
48 UPDATE a SET image=lo_import('/etc/hosts')
49 WHERE fname='empty';
50 SELECT * FROM a
51 WHERE fname LIKE 'empty%';
52 UPDATE a SET image=null
53 WHERE fname='empty';
54 SELECT * FROM a
55 WHERE fname LIKE 'empty%';
56
57 -- delete the entry
58 DELETE FROM a
59 WHERE fname='aa';
60 SELECT * FROM a
61 WHERE fname LIKE 'aa%';
62
63 -- This deletes the table contents. Note, if you comment this out, and
64 -- expect the drop table to remove the objects, think again. The trigger
65 -- doesn't get fired by drop table.
66 DELETE FROM a;
67
68 -- finally drop the table
69 DROP TABLE a;
70
71 -- Check what is in pg_largeobject ... if different from original, trouble
72 SELECT count(DISTINCT loid) FROM pg_largeobject;
73
74 -- end of tests