Search Postgresql Archives

Re: type SERIAL in C host-struct

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

 



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@xxxxxxxxxxx, 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

Attachment: signature.asc
Description: PGP signature


[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 Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux