Search Postgresql Archives

Re: insert ..... returning <column> problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux