pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Michael Ivanov <ivans@isle.spb.ru>
To: pgsql-general@lists.postgresql.org
Subject: Re: insert ..... returning <column> problem
Date: Thu, 24 Jun 2021 16:13:54 +0200
Message-ID: <8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at> (raw)
In-Reply-To: <3d7fba5a-aecd-935d-c7ae-8dbfe8a253f7@isle.spb.ru>
References: <dc22ae8e-e75e-2e2a-8e93-fe9c79de0c91@logit-ag.de>
	<55a5f85f533342d6b4ae4f518a8a29f1f261ce45.camel@cybertec.at>
	<3d7fba5a-aecd-935d-c7ae-8dbfe8a253f7@isle.spb.ru>

On Thu, 2021-06-24 at 16:25 +0300, Michael Ivanov wrote:
> > > I'm trying to insert a record returning column value using the following query:
> > > 
> > >    INSERT INTO t_load (load_id, load_type) VALUES (:id, :typ) returning load_idx INTO :idx
> > > 
> > > But when I try to prepare the query I'm getting the following error:
> > > 
> > >    PREPARE p1515544c00000001 AS insert into t_load (load_id, load_type) values ($1, $2) returning load_idx into $3]:
> > >        ERROR:  syntax error at or near "into" LINE 1: ...ad_id, load_type) values ($1, $2) returning load_idx into $3
> > >                                                                                                               ^
> > > Why 'into var' is not accepted here?
> > 
> > Are you talking about ECPG?
>
> I am using postgres c library, namely I'm calling PQexec()

Then you don't need it.  You may be mixing up SQL syntax and PL/pgSQL syntax.

Just run the statement without the INTO, and it will return a result set, just
like a SELECT would.

By the way, you cannot have parameters with PQexec().
Use PQexecParams() for that.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (6+ messages)  latest in thread

Message-ID: <8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at>
Permalink:  ../8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at/
Also on:    postgresql.org/message-id/8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, ivans@isle.spb.ru
  Subject: Re: insert ..... returning <column> problem
  In-Reply-To: <8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at>
  References: <dc22ae8e-e75e-2e2a-8e93-fe9c79de0c91@logit-ag.de> <55a5f85f533342d6b4ae4f518a8a29f1f261ce45.camel@cybertec.at> <3d7fba5a-aecd-935d-c7ae-8dbfe8a253f7@isle.spb.ru> <8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox