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

From: Michael Ivanov <ivans(at)isle(dot)spb(dot)ru>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: insert ..... returning <column> problem
Date: 2021-06-24 14:29:22
Message-ID: b2d88557-ef9e-5b41-f6d0-15dd000d0e76@isle.spb.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I was just trying to use it similar to oracle handling in "returning COLUMN into :VAR"
So in postgres I should not explicitly specify destination variable for 'returning'
value in query itself, but rather retrieve the result from PGresult returned by PQexec().
ok, thanks for clarification!

On 24.06.2021 17:13, Laurenz Albe wrote:
> 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
>

--
\ / | |
(OvO) | Михаил Иванов |
(^^^) | |
\^/ | E-mail: ivans(at)isle(dot)spb(dot)ru |
^ ^ | |

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2021-06-24 14:31:50 Re: OSX: migrating Postgres db from one Mac to another
Previous Message Laurenz Albe 2021-06-24 14:19:28 Re: How much data does server side "loread" return?