Last active
November 29, 2018 22:46
-
-
Save dlangille/5917df6cd02f731700a729504470ad91 to your computer and use it in GitHub Desktop.
Identical table name and function name in PostgreSQL 11.1
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
CREATE OR REPLACE FUNCTION element_pathname_insert() RETURNS TRIGGER AS $$ | |
BEGIN | |
RAISE WARNING 'element_pathname_insert says: %', NEW.id; | |
INSERT INTO element_pathname (element_id, pathname) | |
VALUES (NEW.id, element_pathname(NEW.id)); | |
RETURN NEW; | |
END | |
$$ LANGUAGE 'plpgsql'; | |
From the definition of the table: element | |
element_pathname_insert AFTER INSERT ON element FOR EACH ROW EXECUTE PROCEDURE element_pathname_insert() |
The duplicate key issue is a red herring, that only occurs because the previous transaction retrieve a '' for element_pathname () and inserted it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The function is: