Created
May 8, 2018 21:18
-
-
Save eyalroth/b0444eb48f736d4e2787b2aa2186c96d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
WITH | |
val (l_name,d_label ) AS | |
(values | |
(? , ?) | |
), | |
ins AS | |
( INSERT INTO | |
label (label_name, device_label) | |
SELECT l_name, d_label FROM val | |
ON CONFLICT ON CONSTRAINT label_name_unique DO NOTHING | |
RETURNING id ,label_name -- only the inserted ones | |
) | |
SELECT COALESCE(ins.id, label.id) AS id | |
FROM val | |
LEFT JOIN ins ON ins.label_name = val.l_name | |
LEFT JOIN label ON label.label_name = val.l_name ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment