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

From: Sándor Daku <daku(dot)sandor(at)gmail(dot)com>
To: ivans(at)isle(dot)spb(dot)ru
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: insert ..... returning <column> problem
Date: 2021-06-24 13:45:16
Message-ID: CAKyoTgYtJqENzp-eAAMAbDR-bahLRd-NihGWaNeUCDupsYyewQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 24 Jun 2021 at 15:25, Michael Ivanov <ivans(at)isle(dot)spb(dot)ru> wrote:

> Hallo, no.
>
> I am using postgres c library, namely I'm calling PQexec()
>
> Best regards,
>
> On 24.06.2021 16:14, Laurenz Albe wrote:
> > On Thu, 2021-06-24 at 12:31 +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?
> >
> > Yours,
> > Laurenz Albe
> >
>
>
> --
> \ / | |
> (OvO) | Михаил Иванов |
> (^^^) | |
> \^/ | E-mail: ivans(at)isle(dot)spb(dot)ru |
> ^ ^ | |
>

Hi,

Client libraries substitute the values(!) of the variables into the sql
queries (Or in this case do a PREPARE and provide the values to that), but
the final query must comply with Postgres syntax.
You can get the values defined in the returning clause from the result set,
like you would do in the case of a SELECT.

Regards,
Sándor

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carlo Poso 2021-06-24 13:53:24 OSX: migrating Postgres db from one Mac to another
Previous Message Carlo Poso 2021-06-24 13:44:27 OSX: migrating Postgres db from one Mac to another