Make libpqsrv_cancel's return const char *, not char *
[pgsql.git] / contrib / lo / lo_test.sql
blob7e52362f81da15725ae4d2d8d82d3bc77953495f
1 /* contrib/lo/lo_test.sql */
3 -- Adjust this setting to control where the objects get created.
4 SET search_path = public;
6 --
7 -- This runs some common tests against the type
8 --
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(oid) FROM pg_largeobject_metadata;
17 -- ignore any errors here - simply drop the table if it already exists
18 DROP TABLE a;
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
30 SELECT * FROM a;
32 -- check that coercion to plain oid works
33 SELECT *,image::oid from a;
35 -- now test the trigger
36 CREATE TRIGGER t_a
37 BEFORE UPDATE OR DELETE ON a
38 FOR EACH ROW
39 EXECUTE PROCEDURE lo_manage(image);
41 -- insert
42 INSERT INTO a VALUES ('aa', lo_import('/etc/hosts'));
43 SELECT * FROM a
44 WHERE fname LIKE 'aa%';
46 -- update
47 UPDATE a SET image=lo_import('/etc/group')::lo
48 WHERE fname='aa';
49 SELECT * FROM a
50 WHERE fname LIKE 'aa%';
52 -- update the 'empty' row which should be null
53 UPDATE a SET image=lo_import('/etc/hosts')
54 WHERE fname='empty';
55 SELECT * FROM a
56 WHERE fname LIKE 'empty%';
57 UPDATE a SET image=null
58 WHERE fname='empty';
59 SELECT * FROM a
60 WHERE fname LIKE 'empty%';
62 -- delete the entry
63 DELETE FROM a
64 WHERE fname='aa';
65 SELECT * FROM a
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.
71 DELETE FROM a;
73 -- finally drop the table
74 DROP TABLE a;
76 -- Check what is in pg_largeobject ... if different from original, trouble
77 SELECT count(oid) FROM pg_largeobject_metadata;
79 -- end of tests