Created
July 17, 2023 17:28
-
-
Save jamesdavidson/9150d8698aee613a7ef47166c4bd6c9f to your computer and use it in GitHub Desktop.
find or create values
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
-- https://stackoverflow.com/a/70312948 | |
WITH | |
extant AS ( | |
SELECT id FROM access_code WHERE ("value") = ('asdf') | |
), | |
inserted AS ( | |
INSERT INTO access_code ("value") | |
SELECT 'asdf' | |
WHERE NOT EXISTS (SELECT FROM extant) | |
RETURNING id | |
) | |
SELECT id FROM inserted | |
UNION ALL | |
SELECT id FROM extant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment