Re: type SERIAL in C host-struct

From: Matthias Apitz <guru(at)unixarea(dot)de>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: type SERIAL in C host-struct
Date: 2019-11-07 19:14:47
Message-ID: 20191107191447.GA2407@c720-r342378
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

El día jueves, noviembre 07, 2019 a las 12:39:39p. m. +0100, Matthias Apitz escribió:

>
> Hello,
>
> We're struggling with the following problem (here show in a simplified
> case).
>
> We have in a PG 11.4 database a table with two columns: SERIAL, VARCHAR(11).
>
> In the ESQL/C pgm the code is:
>
> EXEC SQL BEGIN DECLARE SECTION;
> ...
> struct {
> int ser;
> char name [11];
> } host_struct;
> EXEC SQL END DECLARE SECTION;
>
> an INSERT with
>
> strcpy(host_struct.name, "Sigrid");
> host_struct.ser = 0;
>
> EXEC SQL INSERT INTO lina VALUES (:host_struct);
>
> works but, sets the SERIAL column to 0;
>
> an INSERT with
>
> EXEC SQL INSERT INTO lina VALUES (DEFAULT, :host_struct.name);
>
> works correctly and increments the SERIAL on every INSERT:

At the end of the day we came up with the following solution:

strcpy(host_struct.name, "Sigrid");
EXEC SQL select nextval('lina_lid_seq') into :host_struct.ser;

EXEC SQL INSERT INTO lina VALUES ( :host_struct );

which seems to work fine. Any comments about side effects?
The layout of the table 'lina' is ( serial lid, varchar name )

Thanks,

matthias
--
Matthias Apitz, ✉ guru(at)unixarea(dot)de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub

"Glaube wenig, hinterfrage alles, denke selbst: Wie man Manipulationen durchschaut"
"Believe little, scrutinise all, think by your own: How see through manipulations"
ISBN-10: 386489218X

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Carlos T. Groero Carmona 2019-11-07 19:45:00 Re: pg_hba y ldap
Previous Message Brad Nicholson 2019-11-07 17:18:57 Re: AW: AW: AW: broken backup trail in case of quickly patroni switchback and forth