Last active
January 18, 2025 18:07
-
-
Save sebastianrothbucher/136befdb373ff14e40dbf1b3d066f163 to your computer and use it in GitHub Desktop.
Postgres - insert missing and ignore dups -
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
CREATE TABLE public.test ( | |
id int4 NOT NULL, | |
"text" text NULL, | |
CONSTRAINT test_pkey PRIMARY KEY (id) | |
); | |
insert into test (id, text) values (1, 'hey'), (2, 'ho') on conflict do nothing; | |
insert into test (id, text) values (2, 'hoo'), (3, 'whatever') on conflict do nothing; | |
-- result: 1/hey, 2/ho, 3/whatever inserted - perfect: minimum # statements, exactly what's wanted: just fill in missing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment