2

I have postgres 12.3 and find an error in a simple MERGE statement like below:

MERGE INTO lkup_language a
   USING (SELECT *
            FROM dblc_stg.stg_lkup_home_language
           WHERE home_lang_code NOT IN (SELECT   home_lang_code
                                           FROM dblc_stg.stg_lkup_home_language
                                       GROUP BY home_lang_code
                                         HAVING COUNT (*) > 1)) b
   ON (a.language_cd = b.home_lang_code)
   WHEN NOT MATCHED THEN
      INSERT (a.language_key, a.language_cd, a.language_desc)
      VALUES (NEXTVAL('SEQ_LKUP_LANGUAGE'),b.home_lang_code, b.home_lang_desc)
   WHEN MATCHED THEN
      UPDATE
         SET a.language_desc = b.home_lang_desc   ;

I hope I get some help Thanks Ajay

Adrian Klaver
  • 15,886
  • 2
  • 17
  • 28
Ajay
  • 21
  • 2
  • 2
    Postgres does not have `MERGE`. See `ON CONFLICT` here [Insert](https://www.postgresql.org/docs/current/sql-insert.html). – Adrian Klaver Dec 03 '20 at 15:15
  • 1
    It would be helpful if you could add the specific error message you are receiving to your question as well. – tantalum Dec 03 '20 at 15:18
  • 1
    MERGE doesn't exist in PostgreSQL, the message makes sense. – Frank Heikens Dec 03 '20 at 15:23
  • 1
    You can't just run an Oracle statement in Postgres and expect it to work. Please provide sample data, desired results, and an explanation of the logic you want to implement. – GMB Dec 03 '20 at 15:53
  • Thank you so much !! I spent so much time yesterday on this one, all wasted. I am just trying to convert my oracle script into postgres and there are so many things I am still struggling with. – Ajay Dec 03 '20 at 18:06
  • All valid SQL commands [are listed in the manual](https://www.postgresql.org/docs/current/static/sql-commands.html) –  Dec 03 '20 at 18:18

0 Answers0