From: alex maslakov <alex@serendipia.email>
To: pgsql-committers@lists.postgresql.org
Subject: determine what column(s) form the primary key, in C extention
Date: Mon, 27 Jul 2020 21:08:02 +0530
Message-ID: <2f671cae-a3fe-7064-37d9-68847194ce8d@serendipia.email> (raw)
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?
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-committers@postgresql.org
Cc: alex@serendipia.email
Subject: Re: determine what column(s) form the primary key, in C extention
In-Reply-To: <2f671cae-a3fe-7064-37d9-68847194ce8d@serendipia.email>
References: <2f671cae-a3fe-7064-37d9-68847194ce8d@serendipia.email>
* 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