3

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

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Chintan Patel
  • 721
  • 3
  • 13
  • 30
  • 2
    From the link you posted: **This was never integrated into PostgreSQL, and requires significant work to be production quality** – a_horse_with_no_name 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) – a_horse_with_no_name 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 – a_horse_with_no_name Dec 29 '16 at 07:32

1 Answers1

-3

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,312
  • 7
  • 35
  • 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