3 -- Adjust this setting to control where the objects get created.
4 SET search_path = public;
7 -- This runs some common tests against the type
9 -- It's used just for development
11 -- XXX would be nice to turn this into a proper regression test
14 -- Check what is in pg_largeobject
15 SELECT count(DISTINCT loid) FROM pg_largeobject;
17 -- ignore any errors here - simply drop the table if it already exists
20 -- create the test table
21 CREATE TABLE a (fname name,image lo);
23 -- insert a null object
24 INSERT INTO a VALUES ('empty');
26 -- insert a large object based on a file
27 INSERT INTO a VALUES ('/etc/group', lo_import('/etc/group')::lo);
29 -- now select the table
32 -- check that coercion to plain oid works
33 SELECT *,image::oid from a;
35 -- now test the trigger
37 BEFORE UPDATE OR DELETE ON a
39 EXECUTE PROCEDURE lo_manage(image);
42 INSERT INTO a VALUES ('aa', lo_import('/etc/hosts'));
44 WHERE fname LIKE 'aa%';
47 UPDATE a SET image=lo_import('/etc/group')::lo
50 WHERE fname LIKE 'aa%';
52 -- update the 'empty' row which should be null
53 UPDATE a SET image=lo_import('/etc/hosts')
56 WHERE fname LIKE 'empty%';
57 UPDATE a SET image=null
60 WHERE fname LIKE 'empty%';
66 WHERE fname LIKE 'aa%';
68 -- This deletes the table contents. Note, if you comment this out, and
69 -- expect the drop table to remove the objects, think again. The trigger
70 -- doesn't get fired by drop table.
73 -- finally drop the table
76 -- Check what is in pg_largeobject ... if different from original, trouble
77 SELECT count(DISTINCT loid) FROM pg_largeobject;