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');

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s