MERGE INTO not working with Postgres 9.6

8.9k views Asked by At

In my Postgres 9.6 environment, when I try to execute "MERGE INTO" query, it throws me following error:

ERROR:  syntax error at or near "MERGE"
LINE 1: MERGE INTO Stock USING Buy ON Stock.item_id = Buy.item_id  W...
        ^

It seems like it does not support MERGE query. However when I do google, it seems that MERGE is supported by Postgres since version 9.1.

Please tell me whats going wrong here.

Edit: Following are the sources from where I found MERGE support in Postgres.

https://wiki.postgresql.org/wiki/MergeTestExamples

2

There are 2 answers

1
m-ric On

MERGE aka INSERT ... ON CONFLICT DO NOTHING/UPDATE or UPSERT is only available to postgres 9.5 and later:

Note: MERGE is often used interchangeably with the term UPSERT.

UPSERT functionality will be in the PostgreSQL 9.5 release -- see What's new in PostgreSQL 9.5 MERGE is not in 9.4.5 (the latest PostgreSQL release as of 2015-10-08)

1
Timz On

Postgres does not support the MERGE feature.

See https://www.postgresql.org/docs/9.6/unsupported-features-sql-standard.html

F312 | MERGE statement | consider INSERT ... ON CONFLICT DO UPDATE

Also in the latest version (currently 14) it is not supported.