Created
November 28, 2022 18:10
-
-
Save omerkaya1/11cafc0e205d71c1652c3ff3b3558b2d to your computer and use it in GitHub Desktop.
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
WITH get AS ( | |
SELECT id FROM table_name WHERE name=$1 | |
), new AS ( | |
INSERT INTO table_name (name) VALUES ($1) ON CONFLICT (name) DO NOTHING RETURNING id | |
) | |
SELECT id FROM get | |
UNION ALL | |
SELECT id FROM new; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment