Skip to content

Instantly share code, notes, and snippets.

@rapimo
Created June 12, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rapimo/accac676f7c8e3557a4d to your computer and use it in GitHub Desktop.
Save rapimo/accac676f7c8e3557a4d to your computer and use it in GitHub Desktop.
rowtype cache on trigger
CREATE TABLE foo(
id integer
);
CREATE FUNCTION foo_trigger() RETURNS trigger LANGUAGE plpgsql AS $_$
DECLARE
r foo%rowtype;
BEGIN
SELECT NEW.* INTO r;
RETURN r;
END;
$_$;
CREATE TRIGGER foo AFTER INSERT ON foo FOR EACH ROW EXECUTE PROCEDURE foo_trigger();
INSERT INTO foo VALUES(1);
ALTER TABLE foo ADD COLUMN flag boolean;
INSERT INTO foo VALUES(2);
DROP TABLE foo;
DROP FUNCTION foo_trigger();
@rapimo
Copy link
Author

rapimo commented Jun 12, 2015

results in
ERROR: returned row structure does not match the structure of the triggering table
DETAIL: Number of returned columns (1) does not match expected column count (2).
CONTEXT: PL/pgSQL function foo_trigger() during function exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment