pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Schaber <schabi@logix-tt.com>
To: Julian Scarfe <julian@avbrief.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: NULL becomes default
Date: Sat, 19 Aug 2006 09:51:41 +0200
Message-ID: <44E6C30D.1070608@logix-tt.com> (raw)
In-Reply-To: <029c01c6c228$8e8e5210$0600a8c0@Wilbur>
References: <029c01c6c228$8e8e5210$0600a8c0@Wilbur>

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



view thread (5+ messages)  latest in thread

Message-ID: <44E6C30D.1070608@logix-tt.com>
Permalink:  ../44E6C30D.1070608@logix-tt.com/
Also on:    postgresql.org/message-id/44E6C30D.1070608@logix-tt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: schabi@logix-tt.com, julian@avbrief.com
  Subject: Re: NULL becomes default
  In-Reply-To: <44E6C30D.1070608@logix-tt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox