Re: in C trigger function find out if column is part of primary key

From: Marko Kreen <markokr(at)gmail(dot)com>
To: "Enke, Dr(dot), Michael" <michael(dot)enke(at)wincor-nixdorf(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: in C trigger function find out if column is part of primary key
Date: 2013-04-01 07:25:10
Message-ID: 20130401072510.GA25503@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Apr 01, 2013 at 12:06:25AM +0200, Enke, Dr., Michael wrote:
> I have to find out if a column ( i = 0, ..., tupdesc->natts-1 ) is part of a primary key
> but for performance reasons I do not want to execute another query via SPI.
> Is this possible?

Simpler and probably even faster approach would be to do
catalog lookup via SPI and then cache the result.

The trick here is to get cache invalidation right,
so on any table change cache is refreshed.

You can use PgQ triggers as example:

https://github.com/markokr/skytools/blob/master/sql/pgq/triggers/common.c

It implements various unrelated features, but basics are in
find_table_info() which loads cached data and relcache_reset_cb()
which invalidates.

--
marko

In response to

Browse pgsql-general by date

  From Date Subject
Next Message tushar 2013-04-01 08:03:00 Is 'Peer authentication' supported on HPUX ?
Previous Message Nicholas White 2013-04-01 06:28:13 Re: JDBC Array double precision [] error