I need to check if a row exists or not. If it does not exist, it should be inserted.
This is in postgres
and I am trying to insert row through a shell script. When I run the script it does not show error but it does not insert into table even though no matching row is present.
I like the solution they mention here
INSERT INTO table (id, field, field2)
SELECT 3, 'C', 'Z'
WHERE NOT EXISTS (SELECT 1 FROM table WHERE id=3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With