pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Oskar Stenberg <oskar_stenberg@outlook.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Get primary key of a table through SPI
Date: Thu, 24 Mar 2022 11:59:07 -0400
Message-ID: <3016112.1648137547@sss.pgh.pa.us> (raw)
In-Reply-To: <HE1PR03MB2971CD233611E2872B44ECC0F9199@HE1PR03MB2971.eurprd03.prod.outlook.com>
References: <HE1PR03MB2971CD233611E2872B44ECC0F9199@HE1PR03MB2971.eurprd03.prod.outlook.com>

Oskar Stenberg <oskar_stenberg@outlook.com> writes:
> I need to get the primary keys of a few tables for some code that I'm writing in C. I've found out how to do this through regular SQL code and I know that I can use that SQL code through the SPI. But I was just wondering if there is a better/faster way to get information like this directly through the SPI? I'm imagining something similar to how I can get for example the name of the column with the SPI_fname function? Couldn't find anything when I was looking around, but I might have looked in the wrong place?

SPI doesn't concern itself with such things.  If you're writing C code,
there are a lot of server internal APIs you can use for catalog inquiries
--- in this case, RelationGetPrimaryKeyIndex() might be just what you
want.  However, you may or may not find those convenient to use, and in
any case they're less stable across major versions than the SPI APIs.
So it's a tradeoff.

			regards, tom lane





view thread (2+ messages)

Message-ID: <3016112.1648137547@sss.pgh.pa.us>
Permalink:  ../3016112.1648137547@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3016112.1648137547@sss.pgh.pa.us

 · 

reply

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, oskar_stenberg@outlook.com
  Subject: Re: Get primary key of a table through SPI
  In-Reply-To: <3016112.1648137547@sss.pgh.pa.us>
  References: <HE1PR03MB2971CD233611E2872B44ECC0F9199@HE1PR03MB2971.eurprd03.prod.outlook.com> <3016112.1648137547@sss.pgh.pa.us>

* 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