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 1k07H4-0007Oe-HF for pgsql-committers@arkaria.postgresql.org; Mon, 27 Jul 2020 17:50:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k07H3-00042U-H0 for pgsql-committers@arkaria.postgresql.org; Mon, 27 Jul 2020 17:50:53 +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 1k05Cs-0002Wx-Rb for pgsql-committers@lists.postgresql.org; Mon, 27 Jul 2020 15:38:26 +0000 Received: from mail.pussywipe.pw ([2400:8902::f03c:91ff:fe36:7556]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k05Cm-0005uf-6b for pgsql-committers@lists.postgresql.org; Mon, 27 Jul 2020 15:38:26 +0000 Received: from insignia.local (unknown [IPv6:2409:4042:60d:5af9:e42c:bd33:e4bd:936f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.pussywipe.pw (Postfix) with ESMTPSA id D64EA2064F for ; Mon, 27 Jul 2020 15:38:07 +0000 (UTC) To: pgsql-committers@lists.postgresql.org From: alex maslakov Subject: determine what column(s) form the primary key, in C extention Message-ID: <2f671cae-a3fe-7064-37d9-68847194ce8d@serendipia.email> Date: Mon, 27 Jul 2020 21:08:02 +0530 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hey. I'm creating an extention in C. An extention will be fired as, or inside, a trigger. What I need: dynamically, inside a trigger, identify which column, or columns if the primary key is composed of multiple columns, form the primary key -- their indexes or names. I need a fast way, therefore I don't consider using SPI_exec(..) and the like. I was suggested to use `get_primary_key_attnos` from `src/include/catalog/pg_constraint.h` extern Bitmapset *get_primary_key_attnos(Oid relid, bool deferrableOk) It returns *Bitstamp. And it's got "nwords" and "words[]". But those return just big numbers, not something that look similar to an index of the primary key column. And therefore I haven't had any luck thus far. How to do it?