X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AF8CE9FB28A for ; Sat, 19 Aug 2006 04:51:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 69955-02 for ; Sat, 19 Aug 2006 04:51:22 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 98AEB9FB218 for ; Sat, 19 Aug 2006 04:51:22 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (p549D46FE.dip0.t-ipconnect.de [84.157.70.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 0E36D65950; Sat, 19 Aug 2006 09:53:24 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id D6BBD1819FBAB; Sat, 19 Aug 2006 09:51:41 +0200 (CEST) Message-ID: <44E6C30D.1070608@logix-tt.com> Date: Sat, 19 Aug 2006 09:51:41 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.4 (X11/20060713) MIME-Version: 1.0 To: Julian Scarfe Cc: pgsql-sql@postgresql.org Subject: Re: NULL becomes default References: <029c01c6c228$8e8e5210$0600a8c0@Wilbur> In-Reply-To: <029c01c6c228$8e8e5210$0600a8c0@Wilbur> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.17 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200608/146 X-Sequence-Number: 26104 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