type SERIAL in C host-struct

From: Matthias Apitz <guru(at)unixarea(dot)de>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: type SERIAL in C host-struct
Date: 2019-11-07 11:39:39
Message-ID: 20191107113939.GA130862@sh4-5.1blu.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)unixarea(dot)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!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message İlyas Derse 2019-11-07 13:28:02 SQL SERVER migration to PostgreSql
Previous Message Bibi Mansione 2019-11-07 08:00:45 Re: Hunspell as filtering dictionary