mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Update /contrib for "autocommit TO 'on'".
Create objects in public schema. Make spacing/capitalization consistent. Remove transaction block use for object creation. Remove unneeded function GRANTs.
This commit is contained in:
@ -5,53 +5,65 @@
|
||||
--
|
||||
|
||||
-- ignore any errors here - simply drop the table if it already exists
|
||||
drop table a;
|
||||
DROP TABLE a;
|
||||
|
||||
-- create the test table
|
||||
create table a (fname name,image lo);
|
||||
CREATE TABLE a (fname name,image lo);
|
||||
|
||||
-- insert a null object
|
||||
insert into a values ('null');
|
||||
INSERT INTO a VALUES ('null');
|
||||
|
||||
-- insert an empty large object
|
||||
insert into a values ('empty','');
|
||||
INSERT INTO a VALUES ('empty','');
|
||||
|
||||
-- insert a large object based on a file
|
||||
insert into a values ('/etc/group',lo_import('/etc/group')::lo);
|
||||
INSERT INTO a VALUES ('/etc/group',lo_import('/etc/group')::lo);
|
||||
|
||||
-- now select the table
|
||||
select * from a;
|
||||
SELECT * FROM a;
|
||||
|
||||
-- this select also returns an oid based on the lo column
|
||||
select *,image::oid from a;
|
||||
SELECT *,image::oid from a;
|
||||
|
||||
-- now test the trigger
|
||||
create trigger t_a before update or delete on a for each row execute procedure lo_manage(image);
|
||||
CREATE TRIGGER t_a
|
||||
BEFORE UPDATE OR DELETE ON a
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE lo_manage(image);
|
||||
|
||||
-- insert
|
||||
insert into a values ('aa','');
|
||||
select * from a where fname like 'aa%';
|
||||
INSERT INTO a VALUES ('aa','');
|
||||
SELECT * FROM a
|
||||
WHERE fname LIKE 'aa%';
|
||||
|
||||
-- update
|
||||
update a set image=lo_import('/etc/group')::lo where fname='aa';
|
||||
select * from a where fname like 'aa%';
|
||||
UPDATE a SET image=lo_import('/etc/group')::lo
|
||||
WHERE fname='aa';
|
||||
SELECT * FROM a
|
||||
WHERE fname LIKE 'aa%';
|
||||
|
||||
-- update the 'empty' row which should be null
|
||||
update a set image=lo_import('/etc/hosts')::lo where fname='empty';
|
||||
select * from a where fname like 'empty%';
|
||||
update a set image=null where fname='empty';
|
||||
select * from a where fname like 'empty%';
|
||||
UPDATE a SET image=lo_import('/etc/hosts')::lo
|
||||
WHERE fname='empty';
|
||||
SELECT * FROM a
|
||||
WHERE fname LIKE 'empty%';
|
||||
UPDATE a SET image=null
|
||||
WHERE fname='empty';
|
||||
SELECT * FROM a
|
||||
WHERE fname LIKE 'empty%';
|
||||
|
||||
-- delete the entry
|
||||
delete from a where fname='aa';
|
||||
select * from a where fname like 'aa%';
|
||||
DELETE FROM a
|
||||
WHERE fname='aa';
|
||||
SELECT * FROM a
|
||||
WHERE fname LIKE 'aa%';
|
||||
|
||||
-- This deletes the table contents. Note, if you comment this out, and
|
||||
-- expect the drop table to remove the objects, think again. The trigger
|
||||
-- doesn't get thrown by drop table.
|
||||
delete from a;
|
||||
DELETE FROM a;
|
||||
|
||||
-- finally drop the table
|
||||
drop table a;
|
||||
DROP TABLE a;
|
||||
|
||||
-- end of tests
|
||||
|
Reference in New Issue
Block a user