iam create a table using below command in postgresql.
CREATE TABLE someTable (
id serial primary key,
col1 int NOT NULL,
col2 int NOT NULL,
unique (col1, col2)
);
then am execute 2 insert statements.
insert into someTable (col1,col2) values(1,11),(1,12);its working
insert into someTable (col1,col2) values(1,13),(1,14),(1,11);got error (key(col1,col2)=(1,11) is already exist.
But i need to avoid only duplicate pairs. How it will be possible ?
iam try this with
PostgreSQL 9.5.0 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit and PostgreSQL 9.3 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
but i got error
i need ot put like this after executing two statements.
(1,11),(1,12),(1,13),(1,14)
(1,11)which you have already inserted with the first statement. And as you have definedcol1, col2to be unique, you can't insert the same tuple twice.