pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Get primary key of a table through SPI
2+ messages / 2 participants
[nested] [flat]

* Get primary key of a table through SPI
@ 2022-03-24 15:49 Oskar Stenberg <oskar_stenberg@outlook.com>
  2022-03-24 15:59 ` Re: Get primary key of a table through SPI Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Oskar Stenberg @ 2022-03-24 15:49 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi!

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?

Best Regards
Oskar


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Get primary key of a table through SPI
  2022-03-24 15:49 Get primary key of a table through SPI Oskar Stenberg <oskar_stenberg@outlook.com>
@ 2022-03-24 15:59 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2022-03-24 15:59 UTC (permalink / raw)
  To: Oskar Stenberg <oskar_stenberg@outlook.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-03-24 15:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 15:49 Get primary key of a table through SPI Oskar Stenberg <oskar_stenberg@outlook.com>
2022-03-24 15:59 ` Tom Lane <tgl@sss.pgh.pa.us>

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