Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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