SET NULL on NOT NULL field

SET NULL on NOT NULL field

Post by Christopher Kings-Lynn » Wed, 29 Jan 2003 13:20:51



I just noticed you can do this:

create table blah (
        a not null references test on delete set null
)

Should that be prevented?  It shouldn't be too hard to test for really...

Chris

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command

 
 
 

SET NULL on NOT NULL field

Post by Stephan Sza » Wed, 29 Jan 2003 14:23:54



> I just noticed you can do this:

> create table blah (
>    a not null references test on delete set null
> )

> Should that be prevented?  It shouldn't be too hard to test for really...

Maybe, although I don't think the spec prevents it.  In practice
I'd guess it ends up being a more expensive way of saying no action.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

 
 
 

SET NULL on NOT NULL field

Post by Tom La » Wed, 29 Jan 2003 14:26:10



> I just noticed you can do this:
> create table blah (
>    a not null references test on delete set null
> )
> Should that be prevented?

It already does.  Or did you mean disallow the declaration?  I can't see
anything in SQL92 that recommends disallowing the declaration.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

 
 
 

SET NULL on NOT NULL field

Post by Bruno Wolff I » Thu, 30 Jan 2003 02:03:47


On Mon, Jan 27, 2003 at 21:23:01 -0800,


> > I just noticed you can do this:

> > create table blah (
> >       a not null references test on delete set null
> > )

> > Should that be prevented?  It shouldn't be too hard to test for really...

> Maybe, although I don't think the spec prevents it.  In practice
> I'd guess it ends up being a more expensive way of saying no action.

No. You end up not being able to delete the referenced keys. I tested
this in 7.3 and you get the following message when you try it:
ERROR:  ExecUpdate: Fail to add null value in not null attribute col1

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

 
 
 

SET NULL on NOT NULL field

Post by Stephan Sza » Thu, 30 Jan 2003 02:41:21



> On Mon, Jan 27, 2003 at 21:23:01 -0800,


> > > I just noticed you can do this:

> > > create table blah (
> > >  a not null references test on delete set null
> > > )

> > > Should that be prevented?  It shouldn't be too hard to test for really...

> > Maybe, although I don't think the spec prevents it.  In practice
> > I'd guess it ends up being a more expensive way of saying no action.

> No. You end up not being able to delete the referenced keys. I tested
> this in 7.3 and you get the following message when you try it:
> ERROR:  ExecUpdate: Fail to add null value in not null attribute col1

Right, and NO ACTION shouldn't allow you delete the referenced keys either
except that it gives you a meaningful error message as well. :)  I think
you may have been confusing NO ACTION and CASCADE.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate

message can get through to the mailing list cleanly

 
 
 

SET NULL on NOT NULL field

Post by Christopher Kings-Lynn » Thu, 30 Jan 2003 05:43:00



> > I just noticed you can do this:
> > create table blah (
> >       a not null references test on delete set null
> > )

> > Should that be prevented?

> It already does.  Or did you mean disallow the declaration?  I can't see
> anything in SQL92 that recommends disallowing the declaration.

Hmmm, well you do get the 'failed to update null value in not null field'
when you actually delete something from the foreign table, but I guess
there's no reason to actually ban the declaration, as silly as it is...

Chris

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command