Skip to content

Instantly share code, notes, and snippets.

@igilfanov
Created August 16, 2017 12:52
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 igilfanov/4df5e90d8a88d653132746a223639f45 to your computer and use it in GitHub Desktop.
Save igilfanov/4df5e90d8a88d653132746a223639f45 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION trigger_fooview_before_insert()
RETURNS trigger AS $$
DECLARE _q varchar;
BEGIN
_q := (SELECT execute(('CREATE TABLE IF NOT EXISTS sch.foo (i integer')::text) WHERE NOT EXISTS(SELECT * FROM information_schema.tables WHERE table_schema = 'sch' AND table_name = 'foo')) ;
EXECUTE 'INSERT INTO sch.foo VALUES('|| NEW.i::text ||')';
RETURN NEW;
END;
$$ LANGUAGE plpgsql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment