Postgresql: Check entry before inserting to table

pgsql: If you want to check while insertion statement whether the value exists or not, here’s an example of the syntax

INSERT INTO table1 (field1,field2) SELECT 'value1','value2' WHERE NOT EXISTS (SELECT field1,field2 FROM table1 WHERE field1='value1');

Advertisements