Thread: check

check

From
Matt
Date:
how would you go about enforcing the default value:

I have a nextval('seq') as my default and on an insert I don't want any 
other value to be allowed.

forget my last query about inheritance issues



Re: check

From
"Christopher Kings-Lynne"
Date:
Look at:

http://techdocs.postgresql.org/

Look at the introduction to RULES where they do a read-only column.

Chris

----- Original Message ----- 
From: "Matt" <matthew.berardi@weilpublishing.com>
To: <pgsql-sql@postgresql.org>
Sent: Saturday, June 15, 2002 2:47 AM
Subject: [SQL] check


> how would you go about enforcing the default value:
> 
> I have a nextval('seq') as my default and on an insert I don't want any 
> other value to be allowed.
> 
> forget my last query about inheritance issues
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> 



Re: check

From
Stephan Szabo
Date:
On Fri, 14 Jun 2002, Matt wrote:

> how would you go about enforcing the default value:
>
> I have a nextval('seq') as my default and on an insert I don't want any
> other value to be allowed.

Don't do a default, do a before trigger that sets the value so that even
if a value is specified it uses the sequence anyway (or you could
potentially check that it's currently null and error I guess as well).




Re: check

From
Manfred Koizar
Date:
On Fri, 14 Jun 2002 14:47:32 -0400, Matt
<matthew.berardi@weilpublishing.com> wrote:
>how would you go about enforcing the default value:
>
>I have a nextval('seq') as my default and on an insert I don't want any 
>other value to be allowed.

Matt,
   CREATE TABLE tab (id INTEGER NOT NULL DEFAULT 0, ...

and add a before insert trigger that *unconditionally* puts
nextval('seq') into new.id.  I guess, you don't want to allow your
users to change the id of an existing row, so you might also want to
add a before update trigger that sets new.id to old.id.

ServusManfred