Skip to content

Instantly share code, notes, and snippets.

@sebastianrothbucher
Last active January 18, 2025 18:07
Show Gist options
  • Save sebastianrothbucher/136befdb373ff14e40dbf1b3d066f163 to your computer and use it in GitHub Desktop.
Save sebastianrothbucher/136befdb373ff14e40dbf1b3d066f163 to your computer and use it in GitHub Desktop.
Postgres - insert missing and ignore dups -
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