Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etVTL-0000fr-AG for pgsql-general@arkaria.postgresql.org; Wed, 07 Mar 2018 09:34:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1etVTK-0003yJ-4r for pgsql-general@arkaria.postgresql.org; Wed, 07 Mar 2018 09:34:54 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etVTJ-0003xW-JX for pgsql-general@lists.postgresql.org; Wed, 07 Mar 2018 09:34:53 +0000 Received: from mail-qk0-x22b.google.com ([2607:f8b0:400d:c09::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1etVTE-0001oU-6E for pgsql-general@postgresql.org; Wed, 07 Mar 2018 09:34:49 +0000 Received: by mail-qk0-x22b.google.com with SMTP id v124so1820433qkh.11 for ; Wed, 07 Mar 2018 01:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=NOOnrheXlyOeeP/ta3MPAh6Fv/ncqKC1LHKPOifFF8U=; b=iPqexTViQhNbzdoG48602iAFmGUxFvZYbeR94/Fr+B1lssBkNRddHp+09zucFyro2m fkgNh6NTLHj+k5oQEPg37vKV+Uk9w3btwKUw/V31i/oqzZSfXIAqsDBzOiIyf3JWVGXe R3s836+XdmA2SNIQ4aKKVepfPU7sfjLDnaGow1QoyukJEthPjSCMZv2eeQP5g/N7yv4T pO3TwsnEGvVl14vNxY5hZR5qnPn/HxfVXgOx228UucXRBGj5rDeytHGigF5MH39slMH5 n0vfFPqWcfzAFaKuUwIWzNC3L3+YW82KWt2qZC5+5iqaVGTETa3YXy3pKYTd27VE9Xo2 UAAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=NOOnrheXlyOeeP/ta3MPAh6Fv/ncqKC1LHKPOifFF8U=; b=F6m+Wo2G0+TpSPAEE6s4QwYJiNvXsakqvXtR7ApXt72IdGoS57CinXt774b2Y3xnb9 gfYf9DISdxJGEqkiwo4xIH+7x/+jzAsPKCcjb1k8+RacaEOTKtqHHfr3S7DlKHtVdivM iYOSPJfmuxZpQ+Ph+XgSnNDV/e6nMq4cU3POWr1DQY585IDvwTZ6mz77AUek+7SaHHPx jd3leH5CoipAVCmihe19Qmx3OtDAmx6aa/hgCuD3XxqmXGjyLeo9dCjvq9zKltD9ao2d PdnVF3uu1gEO92KgJ5pn81aFSxVr3F01g64Pk9rS9QK5jhKviitgcEIYHKMSIx3NXb+t RQAA== X-Gm-Message-State: AElRT7HrwhmEUdbg3Asods0xGlDYw+QUgVqSF4eKAo5mHjYH5WnkneFa jHPH+8DfEOQTRJ8plY4sYS7gRw== X-Google-Smtp-Source: AG47ELs8WpmOHaOPVY1zwWAiTBlE1GYM5Ob7caAqMj6fhWwwTTaxhjXp80mtQyhfXghdA6WidkrDxQ== X-Received: by 10.55.191.65 with SMTP id p62mr30408236qkf.88.1520415286961; Wed, 07 Mar 2018 01:34:46 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.34.242]) by smtp.gmail.com with ESMTPSA id q56sm11980048qtb.66.2018.03.07.01.34.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Mar 2018 01:34:46 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 6BC697A5; Wed, 7 Mar 2018 06:34:44 -0300 (-03) Date: Wed, 7 Mar 2018 06:34:44 -0300 From: Alvaro Herrera To: Vinodh NV Cc: pgsql-general Subject: Re: Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "merge". Message-ID: <20180307093444.upjdj2moqep46a6u@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Vinodh NV wrote: > Sir, > > I am facing the error Caused by: org.postgresql.util.PSQLException: ERROR: > syntax error at or near "merge". when I execute the below query in > postgres database. The same works fine in Oracle. > > merge into net n using dual on (n.id=:id) when matched then update set > Status=:status, lastStatusDate=:lastStatusDate, errorMessage=:errorMessage, > errorDetails=:errorDetails when not matched then insert (id,Status, > lastStatusDate, errorMessage, errorDetails) values > (:id,:status,:lastStatusDate,:errorMessage,:errorDetails)"; > > > Can you please let me know how to resolve it? Easy -- just don't use merge with Postgres, as it doesn't support MERGE yet. There's work ongoing to support it, but it will appear in Postgres 11 at the earliest. There exists a nonstandard command INSERT ON CONFLICT DO UPDATE which would probably be useful. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services