Created
May 16, 2018 20:57
-
-
Save verfriemelt-dot-org/76c7de20bde461aef99a7e38a8ae571a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS test CASCADE; | |
DROP FUNCTION IF EXISTS test2; | |
CREATE TABLE test ( | |
a INTEGER NOT NULL, | |
b INTEGER NOT NULL | |
); | |
CREATE OR REPLACE FUNCTION test2() RETURNS TRIGGER AS $$ | |
BEGIN | |
PERFORM test3(new); | |
END $$ LANGUAGE plpgsql; | |
CREATE TRIGGER test AFTER INSERT OR UPDATE | |
ON test FOR EACH ROW | |
EXECUTE PROCEDURE test2(); | |
CREATE OR REPLACE FUNCTION test3(IN src test) RETURNS VOID AS $$ | |
BEGIN | |
RAISE EXCEPTION 'expected c to be 1: %',src.c; | |
END $$ LANGUAGE plpgsql; | |
ALTER TABLE test ADD COLUMN c INTEGER NOT NULL; | |
-- insert in same session yields | |
-- testdb=# INSERT INTO test (a,b,c) VALUES (1,1,1); | |
-- ERROR: record "src" has no field "c" | |
INSERT INTO test (a,b,c) VALUES (1,1,1); | |
-- after reconnect to db | |
INSERT INTO test (a,b,c) VALUES (2,2,2); | |
-- testdb=# INSERT INTO test (a,b,c) VALUES (1,1,1); | |
-- ERROR: expected c to be 1: 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment