Skip to content

Instantly share code, notes, and snippets.

@serverhorror
Created December 5, 2017 13:46
Show Gist options
  • Save serverhorror/b0edc0eb5c6c100ac380fbd96fbf46d2 to your computer and use it in GitHub Desktop.
Save serverhorror/b0edc0eb5c6c100ac380fbd96fbf46d2 to your computer and use it in GitHub Desktop.
WITH
sel AS (SELECT id, key, value FROM labels WHERE (key = 'sequencing_strandness' AND value = 'paired-end')),
ins AS (
INSERT INTO "labels"(key, value)
SELECT key, value
WHERE NOT EXISTS (SELECT 1 FROM sel)
RETURNING "id", key, value
)
SELECT * FROM ins UNION ALL SELECT * FROM sel
;
ERROR: column "key" does not exist
LINE 5: SELECT key, value
^
HINT: There is a column named "key" in table "labels", but it cannot be referenced from this part of the query.
Time: 2.784 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment