Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get primary keys dynamically, via a C extention #4

Open
naddika opened this issue Jun 3, 2020 · 1 comment
Open

Get primary keys dynamically, via a C extention #4

naddika opened this issue Jun 3, 2020 · 1 comment

Comments

@naddika
Copy link

naddika commented Jun 3, 2020

This isn't directly related to this project; perhaps you know the answer:

I'm writting an extention in C. It's a function for a trigger. I need to dynamically identify which column, or columns, if the primary key is composed of multiple columns, is the primary key -- their indexes or names.

I suppose, the function get_primary_key_attnos can help me.

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.

Therefore, I haven't been able to figure out how to proceed with it and identify the primary key. Any idea?

@RhodiumToad
Copy link
Collaborator

You should ask this on the pgsql-general mailing list or on the #postgresql irc channel on freenode.

But a Bitmapset is a set of small integers represented as a bitmap, and there are functions to iterate over it and return the contained integer values; these are the attnos of the primary key columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants