Skip to content

Instantly share code, notes, and snippets.

@Benjaminhu
Created August 23, 2020 11:43
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 Benjaminhu/28df2417e96f579568ceade9c9768b25 to your computer and use it in GitHub Desktop.
Save Benjaminhu/28df2417e96f579568ceade9c9768b25 to your computer and use it in GitHub Desktop.
PostgreSQL self-check config insert template
INSERT INTO
config (id, host, section, name, value)
SELECT
nextval('seq_config'::text), new.host, new.section, new.name, new.value
FROM (
SELECT DISTINCT host, '<SECTION>' AS section, '<NAME>' AS name, '<VALUE>' AS value FROM config
) AS new
WHERE NOT EXISTS (
SELECT notexists.host
FROM config AS notexists
WHERE notexists.section = new.section AND notexists.name = new.name AND notexists.host = new.host
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment