| From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
|---|---|
| To: | alex maslakov <alex(at)serendipia(dot)email> |
| Cc: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: determine what column(s) form the primary key, in C extention |
| Date: | 2020-07-27 21:50:39 |
| Message-ID: | CAApHDvqr8niZ=BaNox5MsMQpZmTk9FnpSekwk2znRehRw37E9Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers pgsql-general |
Hi Alex,
On Tue, 28 Jul 2020 at 05:47, alex maslakov <alex(at)serendipia(dot)email> wrote:
> 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?
You'll need to loop over the return value of that function with
bms_next_member()
e.g.
pkattnos = get_primary_key_attnos(oid, false);
i = -1;
while ((i = bms_next_member(pkattnos , i)) >= 0)
{
/* do stuff with i */
/* you'll need to use i - FirstLowInvalidHeapAttributeNumber to get
the pg_attribute.attnum */
}
For the future, for questions, you should use the general list. If
the question is very source code related then you might have more luck
in pgsql-hackers. This is not the right list. Please post any
followup questions on one of those lists.
Note the description for this list, per
https://www.postgresql.org/list/ is "Notification of git commits are
sent to this list. Do not post here!"
David
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Geoghegan | 2020-07-28 00:54:30 | pgsql: Remove hashagg_avoid_disk_plan GUC. |
| Previous Message | alex maslakov | 2020-07-27 15:38:02 | determine what column(s) form the primary key, in C extention |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alvaro Herrera | 2020-07-27 22:00:43 | Re: bad JIT decision |
| Previous Message | Michael Lewis | 2020-07-27 20:03:42 | Re: Format generation_expression |