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 1iSnFB-0004Q0-VL for pgsql-general@arkaria.postgresql.org; Thu, 07 Nov 2019 19:14:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSnFA-0003H9-NA for pgsql-general@arkaria.postgresql.org; Thu, 07 Nov 2019 19:14:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSnFA-0003H2-A7 for pgsql-general@lists.postgresql.org; Thu, 07 Nov 2019 19:14:56 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iSnF6-0006f6-Qt for pgsql-general@lists.postgresql.org; Thu, 07 Nov 2019 19:14:55 +0000 Received: from [87.152.182.222] (helo=localhost.unixarea.de) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.86_2) (envelope-from ) id 1iSnF2-0004Ya-NL; Thu, 07 Nov 2019 20:14:48 +0100 Received: from localhost.my.domain (localhost [127.0.0.1]) by localhost.unixarea.de (8.15.2/8.14.9) with ESMTPS id xA7JEl4q002515 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 7 Nov 2019 20:14:48 +0100 (CET) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by localhost.my.domain (8.15.2/8.14.9/Submit) id xA7JElD9002514; Thu, 7 Nov 2019 20:14:47 +0100 (CET) (envelope-from guru@unixarea.de) X-Authentication-Warning: localhost.my.domain: guru set sender to guru@unixarea.de using -f Date: Thu, 7 Nov 2019 20:14:47 +0100 From: Matthias Apitz To: pgsql-general@lists.postgresql.org Subject: Re: type SERIAL in C host-struct Message-ID: <20191107191447.GA2407@c720-r342378> Reply-To: Matthias Apitz References: <20191107113939.GA130862@sh4-5.1blu.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline In-Reply-To: <20191107113939.GA130862@sh4-5.1blu.de> X-Operating-System: FreeBSD 13.0-CURRENT r342378 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.11.1 (2018-12-01) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 87.152.182.222 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable El d=C3=ADa jueves, noviembre 07, 2019 a las 12:39:39p. m. +0100, Matthias = Apitz escribi=C3=B3: >=20 > Hello, >=20 > We're struggling with the following problem (here show in a simplified > case). >=20 > We have in a PG 11.4 database a table with two columns: SERIAL, VARCHAR(1= 1). >=20 > In the ESQL/C pgm the code is: >=20 > EXEC SQL BEGIN DECLARE SECTION; > ... > struct { > int ser; > char name [11]; > } host_struct; > EXEC SQL END DECLARE SECTION; >=20 > an INSERT with >=20 > strcpy(host_struct.name, "Sigrid"); > host_struct.ser =3D 0; >=20 > EXEC SQL INSERT INTO lina VALUES (:host_struct); >=20 > works but, sets the SERIAL column to 0; >=20 > an INSERT with >=20 > EXEC SQL INSERT INTO lina VALUES (DEFAULT, :host_struct.name); >=20 > 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 ); =20 which seems to work fine. Any comments about side effects? The layout of the table 'lina' is ( serial lid, varchar name ) Thanks, matthias --=20 Matthias Apitz, =E2=9C=89 guru@unixarea.de, 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 durc= hschaut" "Believe little, scrutinise all, think by your own: How see through manipul= ations" ISBN-10: 386489218X --CE+1k2dSO48ffgeK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXmn7rBYYViyzy/vBR8z35Hb+nREFAl3EbRAACgkQR8z35Hb+ nRGdGA//dQLr6cYWzDQ4czV87TMH/X8wnFqxwDlX66EJCZ6AAlM9O33M9qfgqOMT 0j3IjUEkxFUATAZdk/cY2r+6DCepaeSvSLLjgMPwoQ/TVEYOl/ptD1DvGc/lT6Rq FJjlUJjZct099TITBWKm6AVm2C8i4qABTnHuARHFw2/Vr8+8ZmfTg2TW2/rQY1EL jxqMjc+I3f86bXgy5CGRJeR/HxMrZXRrG9ZuHBHBMQLN679xdoXxYqKJb/0KRNs2 D3mM0sE3SshoZdv2/lLacndNaOPqYnTvXSTKbTyh7xE7iSoxP5XuO6kAcFWR0fwj BSdDZ9Fazfqw3/2O4v7OTwEsf2+gdPFNGU47VBakXxkOOhht6a1TCqwUmtQaBNrA JADUwlFu6Ba5G/+MGzPDQy1O8fitPxMAamWf4GPgTmNJIlojullowf6N0rlMKq7m ntfazm3PtjEqn9h7XCWg18sw3z9RdG2U3p2BR1y5mVYy0Fx+92DWJSK17Z0gxvsJ siD7h8qKTGGSQcEZrqMoTirxB7q1uoIyQBxeq1XaohoFASqGg0wpa4nOhQXnXeo/ BeGgEyuUrsIU3C/YF6CDT//ibaOhvkKnxuzTuJIdPBl1PsUcEVPnUQwStkklcILJ Yznpi7tgxSQCk/KvuSOuADztIjeu+cXriO/lNP+rzDI0kKP8i2E= =9K8t -----END PGP SIGNATURE----- --CE+1k2dSO48ffgeK--