2 -- This runs some common tests against the type
4 -- It's used just for development
6 -- XXX would be nice to turn this into a proper regression test
9 -- Check what is in pg_largeobject
10 SELECT count(DISTINCT loid) FROM pg_largeobject;
12 -- ignore any errors here - simply drop the table if it already exists
15 -- create the test table
16 CREATE TABLE a (fname name,image lo);
18 -- insert a null object
19 INSERT INTO a VALUES ('empty');
21 -- insert a large object based on a file
22 INSERT INTO a VALUES ('/etc/group', lo_import('/etc/group')::lo);
24 -- now select the table
27 -- check that coercion to plain oid works
28 SELECT *,image::oid from a;
30 -- now test the trigger
32 BEFORE UPDATE OR DELETE ON a
34 EXECUTE PROCEDURE lo_manage(image);
37 INSERT INTO a VALUES ('aa', lo_import('/etc/hosts'));
39 WHERE fname LIKE 'aa%';
42 UPDATE a SET image=lo_import('/etc/group')::lo
45 WHERE fname LIKE 'aa%';
47 -- update the 'empty' row which should be null
48 UPDATE a SET image=lo_import('/etc/hosts')
51 WHERE fname LIKE 'empty%';
52 UPDATE a SET image=null
55 WHERE fname LIKE 'empty%';
61 WHERE fname LIKE 'aa%';
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.
68 -- finally drop the table
71 -- Check what is in pg_largeobject ... if different from original, trouble
72 SELECT count(DISTINCT loid) FROM pg_largeobject;