pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthias Apitz <guru@unixarea.de>
To: pgsql-general@lists.postgresql.org
Subject: type SERIAL in C host-struct
Date: Thu, 7 Nov 2019 12:39:39 +0100
Message-ID: <20191107113939.GA130862@sh4-5.1blu.de> (raw)


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!





view thread (5+ messages)  latest in thread

Message-ID: <20191107113939.GA130862@sh4-5.1blu.de>
Permalink:  ../20191107113939.GA130862@sh4-5.1blu.de/
Also on:    postgresql.org/message-id/20191107113939.GA130862@sh4-5.1blu.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: guru@unixarea.de
  Subject: Re: type SERIAL in C host-struct
  In-Reply-To: <20191107113939.GA130862@sh4-5.1blu.de>
  References: <20191107113939.GA130862@sh4-5.1blu.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox