pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Horoschun <mhoroschun@canprint.com.au>
To: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-sql@postgresql.org
Subject: Re: Knowing when it is safe to call currval()
Date: Mon, 12 May 2003 00:28:33 +1000
Message-ID: <D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au> (raw)
In-Reply-To: <20030511133513.GA22780@wolff.to>

Hi Bruno,

Thanks for your assistance.

>> I have a bunch of SECURITY DEFINER functions that are called from
>> TRIGGERS which force the primary key of tables to the next value in a
>> sequence. Normal users can't call nextval() or setval() on any
>> sequences. The triggers basically do:
>
> One way out of this using a different approach might be to make 
> security
> definer functions that will let normal users call nextval for the
> sequences. You could then use these as the default for the appropiate
> columns.
>
> Along the way you are doing things, instead of checking to see if
> the row is not equal to currval, perhaps check to see if it is null.
> Then you could supply a value of null when you want it to be rewritten.
>

I've decided to do something similar to this. I'm now only doing the 
currval() check if the user-supplied value is not null.

IF NEW.a_id IS NOT NULL THEN
     IF NEW.a_id <> currval( 'a_id_seq' ) THEN
	    RAISE EXCEPTION 'a_id must be NULL or the current a_id_seq value.';
     END IF;
ELSE
     NEW.a_id := nextval( 'a_id_seq'::text );
END IF;

It is a bit of a kludge, but I painted myself into the corner in the 
first place!

Cheers

Matthew.




view thread (4+ messages)

Message-ID: <D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au>
Permalink:  ../D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au/
Also on:    postgresql.org/message-id/D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au

 · 

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-sql@postgresql.org
  Cc: mhoroschun@canprint.com.au, bruno@wolff.to
  Subject: Re: Knowing when it is safe to call currval()
  In-Reply-To: <D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au>
  References: <20030511133513.GA22780@wolff.to> <D8510367-83BC-11D7-AF24-000393B3A702@canprint.com.au>

* 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