Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSg8i-0004Qb-8M for pgsql-general@arkaria.postgresql.org; Thu, 07 Nov 2019 11:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSg8f-00078p-PL for pgsql-general@arkaria.postgresql.org; Thu, 07 Nov 2019 11:39:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSg8f-00078h-FZ for pgsql-general@lists.postgresql.org; Thu, 07 Nov 2019 11:39:45 +0000 Received: from smh-06.1blu.de ([178.254.0.206]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSg8c-0007hQ-9Y for pgsql-general@lists.postgresql.org; Thu, 07 Nov 2019 11:39:45 +0000 Received: from [172.16.29.5] (helo=sh4-5.1blu.de) by smh-06.1blu.de with esmtp (Exim 4.86_2) (envelope-from ) id 1iSg8Z-0001f4-EA; Thu, 07 Nov 2019 12:39:39 +0100 Received: from ftp51246-2575596 by sh4-5.1blu.de with local (Exim 4.86_2) (envelope-from ) id 1iSg8Z-000aJv-A5; Thu, 07 Nov 2019 12:39:39 +0100 Date: Thu, 7 Nov 2019 12:39:39 +0100 From: Matthias Apitz To: pgsql-general@lists.postgresql.org Subject: type SERIAL in C host-struct Message-ID: <20191107113939.GA130862@sh4-5.1blu.de> Reply-To: Matthias Apitz MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Operating-System: FreeBSD 12.0-CURRENT r314251 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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!