OSDN Git Service

9acc47debda5d462bfd5b159a20814e38975b931
[pg-rex/syncrep.git] / 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
7 -- ignore any errors here - simply drop the table if it already exists
8 DROP TABLE a;
9
10 -- create the test table
11 CREATE TABLE a (fname name,image lo);
12
13 -- insert a null object
14 INSERT INTO a VALUES ('null');
15
16 -- insert an empty large object
17 INSERT INTO a VALUES ('empty','');
18
19 -- insert a large object based on a file
20 INSERT INTO a VALUES ('/etc/group',lo_import('/etc/group')::lo);
21
22 -- now select the table
23 SELECT * FROM a;
24
25 -- this select also returns an oid based on the lo column
26 SELECT *,image::oid from a;
27
28 -- now test the trigger
29 CREATE TRIGGER t_a
30 BEFORE UPDATE OR DELETE ON a
31 FOR EACH ROW
32 EXECUTE PROCEDURE lo_manage(image);
33
34 -- insert
35 INSERT INTO a VALUES ('aa','');
36 SELECT * FROM a
37 WHERE fname LIKE 'aa%';
38
39 -- update
40 UPDATE a SET image=lo_import('/etc/group')::lo
41 WHERE fname='aa';
42 SELECT * FROM a
43 WHERE fname LIKE 'aa%';
44
45 -- update the 'empty' row which should be null
46 UPDATE a SET image=lo_import('/etc/hosts')::lo
47 WHERE fname='empty';
48 SELECT * FROM a
49 WHERE fname LIKE 'empty%';
50 UPDATE a SET image=null
51 WHERE fname='empty';
52 SELECT * FROM a
53 WHERE fname LIKE 'empty%';
54
55 -- delete the entry
56 DELETE FROM a
57 WHERE fname='aa';
58 SELECT * FROM a
59 WHERE fname LIKE 'aa%';
60
61 -- This deletes the table contents. Note, if you comment this out, and
62 -- expect the drop table to remove the objects, think again. The trigger
63 -- doesn't get thrown by drop table.
64 DELETE FROM a;
65
66 -- finally drop the table
67 DROP TABLE a;
68
69 -- end of tests