type SERIAL in C host-struct - Mailing list pgsql-general

From Matthias Apitz
Subject type SERIAL in C host-struct
Date
Msg-id 20191107113939.GA130862@sh4-5.1blu.de
Whole thread Raw
Responses Re: type SERIAL in C host-struct  (Matthias Apitz <guru@unixarea.de>)
List pgsql-general
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:

printf "select * from lina WHERE name = 'Sigrid';\n" | psql -Usisis -d newsisis
 lid |         name
-----+----------------------
  28 | Sigrid
  29 | Sigrid
   0 | Sigrid   <*********** this was with host_struct.ser = 0;
  30 | Sigrid
  31 | Sigrid

How the value for host_struct.ser must be given, as we do not want to
name all the struct members in the INSERT statement(s), the real structs
have plenty much columns, some ~30.

Thanks

    matttias
-- 
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
May, 9: Спаси́бо освободители! Thank you very much, Russian liberators!



pgsql-general by date:

Previous
From: Bibi Mansione
Date:
Subject: Re: Hunspell as filtering dictionary
Next
From: İlyas Derse
Date:
Subject: SQL SERVER migration to PostgreSql