Re: Change the behaviour of the SERIAL "Type"

From: Randall Lucas <rlucas(at)tercent(dot)net>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Dani Oderbolz <oderbolz(at)ecologic(dot)de>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Change the behaviour of the SERIAL "Type"
Date: 2003-06-26 16:05:17
Message-ID: FA785BC0-A7EF-11D7-8248-000A957653D6@tercent.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Wow, I had never actually faced this problem (yet) but I spied it as a
possible stumbling block for porting MySQL apps, for which the standard
practice is inserting a NULL. As I have made a fairly thorough reading
of the docs (but may have not cross-correlated every piece of data yet,
obviously), I was surprised to find I hadn't figured this out myself.
It /seems/ obvious in retrospect, but it really baked my noodle when I
first looked at some ugly MySQL queries.

Respectfully, then, I move that a sentence outlining this functionality
be added to User Manual section 5.1.4, "The Serial Types."
Furthermore, anyone who has written or is writing a MySQL porting guide
should include this, if he hasn't.

Best,

Randall

On Thursday, June 26, 2003, at 08:49 AM, Bruno Wolff III wrote:

> On Thu, Jun 26, 2003 at 14:31:34 +0200,
> Dani Oderbolz <oderbolz(at)ecologic(dot)de> wrote:
>>
>> It was written for MySQL, which can take NULL and then assign an
>> auto_increment.
>> However, in PostgreSQL I am getting problems, because it would not let
>> me insert NULL
>> into a NOT NULL column (which is perfectly sensible from my point of
>> view).
>> But as the author has also left out the column list in the insert, its
>> really tedious to change
>> the code.
>
> You can use the keyword DEFAULT instead of NULL and it will do what you
> want.
>
>> This way, there would be no possibility to circumvent the Value which
>> comes from the Sequence.
>
> You can use a unique constraint to enforce uniqueness.
>
>> Is there a way to change SERIAL this way?
>
> Well you can certainly write your own trigger to do this.
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael A Nachbaur 2003-06-26 16:14:41 Temporary table performance?
Previous Message Bruce Young 2003-06-26 15:05:44 contrib/tsearch - chopped words?