I want to insert a row into postgresql if not exist into table. My table structure is as below.
Table Name: test
id serial NOT NULL
unitid integer
eventid integer
date_time timestamp without time zone
I tried following query but gives me error near Select.
INSERT INTO test VALUES (905, 10, '2015-09-23 13:34:26')
SELECT 905, 10, '2015-09-23 13:34:26'
WHERE NOT EXISTS(
SELECT 1
FROM test
WHERE unitid = 905 AND eventid = 10 AND date_time = '2015-09-23 13:34:26'
);
Please any one give me good suggestion about it. I want faster way to do this.