Re: [HACKERS] Serial and NULL values

From: wieck(at)debis(dot)com (Jan Wieck)
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: maillist(at)candle(dot)pha(dot)pa(dot)us, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Serial and NULL values
Date: 1999-10-30 13:36:55
Message-ID: m11hYgh-0003kLC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> writes:
> >> Offhand I don't see any fundamental reason why serial columns should
> >> be restricted to be nonnull, but evidently someone did at some point.
>
> > The actual null is not the issue. The issue is that if we have a
> > SERIAL column, and we try to put a NULL in there, shouldn't it put the
> > default sequence number in there?
>
> No, I wouldn't expect that at all. A default is inserted when you
> don't supply anything at all for the column. Inserting an explicit
> NULL means you want a NULL, and barring a NOT NULL constraint on
> the column, that's what the system ought to insert. I can see no
> possible justification for creating a type-specific exception to
> that behavior.
>
> If the original asker really wants to substitute something else for
> an explicit null insertion, he could do it with a rule or a trigger.
> But I don't think SERIAL ought to act that way all by itself.
>
> regards, tom lane

I agree with tom.

If you don't want the user to be able to insert NULL, specify
NOT NULL explicitly. And if you want to force a default
behaviour, use a trigger (a rule can't do - sorry).

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#========================================= wieck(at)debis(dot)com (Jan Wieck) #

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 1999-10-30 15:33:00 missing mugshots
Previous Message Theo Kramer 1999-10-30 12:11:35 Re: [HACKERS] postgres inode q's