Re: NULL becomes default

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: Julian Scarfe <julian(at)avbrief(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: NULL becomes default
Date: 2006-08-19 07:51:41
Message-ID: 44E6C30D.1070608@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi, Julian,

Julian Scarfe wrote:
> A surrogate key has been introduced on a table with modifiers:
>
> Column | Type | Modifiers
> -------------+-----------------------------+------------------------------------------------------------
>
> new_id | integer | not null default
> nextval(('some_id_seq'::text)::regclass)
>
> However, some legacy software inserts into the table by first getting
> column names and then composing an INSERT for all the columns, filling
> in any undefined values with NULLs.
>
> Thus when it attempts to insert a row I get a:
>
> ERROR: null value in column "new_id" violates not-null constraint
>
> Thus I would like NULLs in such INSERTs to be treated as DEFAULT rather
> than violating the constraint. Is there an easy way to do that at the
> database level?

Did you try a "before insert" trigger that checks new_id for null
values, and replaces it with nextval()?

Markus

--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf. | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Julian Scarfe 2006-08-20 10:34:48 Re: NULL becomes default
Previous Message Michael Fuhr 2006-08-19 01:01:21 Re: trigger needs to check in multiple tables.