2

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

Chintan Patel
  • 729
  • 3
  • 14
  • 31
  • 3
    From the link you posted: **This was never integrated into PostgreSQL, and requires significant work to be production quality** –  Dec 29 '16 at 07:25
  • Possible duplicate of [How to UPSERT (MERGE, INSERT ... ON DUPLICATE UPDATE) in PostgreSQL?](http://stackoverflow.com/questions/17267417/how-to-upsert-merge-insert-on-duplicate-update-in-postgresql) –  Dec 29 '16 at 07:30
  • The only authoritative source for the existence or syntax of a statement is the [**the manual**](https://www.postgresql.org/docs/current/static/index.html) not some random googling or a wiki page that clearly states that the functionality has not bee integrated into Postgres –  Dec 29 '16 at 07:32

2 Answers2

0

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.

Timz
  • 412
  • 2
  • 13
  • 1
    It will be included in the upcoming [version15](https://www.postgresql.org/docs/15/sql-merge.html) –  Jun 24 '22 at 09:22
-4

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)

m-ric
  • 5,621
  • 7
  • 38
  • 51
  • The OP stated that it was not working on PostgreSQL 9.6. Granted, it didn't work in 9.1, but that isn't the issue. – Doug May 30 '18 at 17:15