I'm changing queries from an Oracle Database to PostgreSQL, and in this query I am getting this error:
ERROR: syntax error at or near "ON"
the query is:
WITH d as (
SELECT ? AS summary, ? AS eventTime), ai as (select * from alarm)
ON (ai.fault_id=? AND ai.external_key=?)
INSERT INTO alarm AS ai(
alarm_id,
fault_id,
external_key)
VALUES (nextval('seq_alrm_instnc_alrm_instnc_id'),?,?)
ON CONFLICT DO UPDATE SET
(${buildUpdateAttributes(attributes)}
ai.summary = d.summary,
ai.system_last_update_time = default,
ai.event_sequence_number =
CASE
WHEN (d.event_number > ai.event_number) THEN d.event_number
ELSE ai.event_number
END)
I am using JDBC to connect to the database and here is the call code
try (PreparedStatement ps = super.prepareStatement_(sql_query)) {
PreparedStatementHelper psh = new PreparedStatementHelper(ps);
psh.add(attribute1);
...
ps.execute()
I have tried different aproaches and taken a long look at Postgres documentation and cannot find what is wrong and didn't find any answer to this specific situation