Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwM4v-0001hM-Os for pgsql-general@arkaria.postgresql.org; Wed, 01 Jun 2022 10:59:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nwM4t-0002oh-I5 for pgsql-general@arkaria.postgresql.org; Wed, 01 Jun 2022 10:59:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwM4t-0002oY-75 for pgsql-general@lists.postgresql.org; Wed, 01 Jun 2022 10:59:51 +0000 Received: from smh-06.1blu.de ([178.254.0.206]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwM4o-0003BA-Iy for pgsql-general@lists.postgresql.org; Wed, 01 Jun 2022 10:59:50 +0000 Received: from [172.16.29.5] (helo=sh4-5.1blu.de) by smh-06.1blu.de with esmtp (Exim 4.90_1) (envelope-from ) id 1nwM4n-0003iy-5C; Wed, 01 Jun 2022 12:59:45 +0200 Received: from localhost ([127.0.0.1]) by sh4-5.1blu.de with esmtp (Exim 4.90_1) (envelope-from ) id 1nwM4n-0003aT-2N; Wed, 01 Jun 2022 12:59:45 +0200 Date: Wed, 1 Jun 2022 12:59:45 +0200 From: Matthias Apitz To: pgsql-general@lists.postgresql.org Subject: function currtid2() in SQL and ESQL/C to get the new CTID of a row Message-ID: <20220601105945.GA18@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.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk While looking for a way to get the new CTID of an UPDATEd row, I came accros this function currtid2() which works fine on SQL with a 14.1 server: https://www.postgresql.org/message-id/Pine.BSO.4.44.0206031939050.21627-100000%40kitten.greentechnologist.org testdb=# SELECT ctid, * FROM dbctest WHERE tstint = 10; ctid | tstchar25 | tstint -------+-----------+-------- (0,9) | | 10 testdb=# UPDATE dbctest SET tstint = 11 WHERE tstint = 10; UPDATE 1 testdb=# SELECT currtid2('dbctest'::text, '(0,9)'::tid); currtid2 ---------- (0,10) checking if it (0,10) is really the new CTID: testdb=# SELECT ctid, * FROM dbctest WHERE tstint = 11; ctid | tstchar25 | tstint --------+-----------+-------- (0,10) | | 11 So far so good, but we do need this in ESQL/C. There the code looks as: EXEC SQL BEGIN DECLARE SECTION; char stmt[255]; static char newCTID[80]; EXEC SQL END DECLARE SECTION; memset(stmt, 0, sizeof(stmt)); sprintf(stmt, "currtid2('%s'::text, '%s'::tid)", table, oldCTID); fprintf(stderr, stmt); fprintf(stderr, "\n"); EXEC SQL SELECT :stmt INTO :newCTID; sprintf(stmt, "table %s oldCTID %s newCTID %s\n", table, oldCTID, newCTID); fprintf(stderr, stmt); The code runs fine but the content of the host variable is the statement itself 'currtid2('dbctest'::text, '(0,13)'::tid)' like the SELECT was just an echo function. Is this function currtid2() not meant to be used in ESQL/C? Or did we something wrong in ESQL/C? I read as well in some posting that the functions currtid2() and currtid() should be removed... Is there some better way to get the new CTID based on the known old (invalid) CTID? Thanks matthias -- Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045 Public GnuPG key: http://www.unixarea.de/key.pub