Help for this page

Select Code to Download


  1. or download this
    drop   table if exists testtable;
    create table           testtable (pk int primary key, foo text, bar te
    +xt);
    ...
    INSERT INTO testtable (pk, foo, bar) VALUES (1, 'Hello', 'World') ON C
    +ONFLICT (pk,foo,bar) DO NOTHING;
    INSERT INTO testtable (pk, foo, bar) VALUES (1, 'Hello', 'World') ON C
    +ONFLICT (pk,foo,bar) DO NOTHING;
    INSERT INTO testtable (pk, foo, bar) VALUES (1, 'Hello', 'Quz'  ) ON C
    +ONFLICT (pk,foo,bar) DO NOTHING;
    
  2. or download this
    drop   table if exists testtable;
    DROP TABLE
    ...
    INSERT INTO testtable (pk, foo, bar) VALUES (1, 'Hello', 'Quz'  ) ON C
    +ONFLICT (pk,foo,bar) DO NOTHING;
    ERROR:  duplicate key value violates unique constraint "testtable_pkey
    +"
    DETAIL:  Key (pk)=(1) already exists.