X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EFFAC14B2827 for ; Wed, 11 Aug 2004 10:34:21 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91645-02 for ; Wed, 11 Aug 2004 13:34:16 +0000 (GMT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 28AA914B281C for ; Wed, 11 Aug 2004 10:34:15 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 1ButFA-000Mno-0V; Wed, 11 Aug 2004 13:34:17 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id D90A0166D7; Wed, 11 Aug 2004 14:34:14 +0100 (BST) Message-ID: <411A2057.60109@archonet.com> Date: Wed, 11 Aug 2004 14:34:15 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Lars Erik Thorsplass Cc: pgsql-sql@postgresql.org Subject: Re: Inserts with incomplete rows... NOT NULL constraints References: <7eeb33a040811053563894d7b@mail.gmail.com> In-Reply-To: <7eeb33a040811053563894d7b@mail.gmail.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/84 X-Sequence-Number: 18581 Lars Erik Thorsplass wrote: > The problem am now facing is that postgres will try to insert a NULL > value for fields not specified in the insert query and that are > defined as NOT NULL in the table structure. Is this the correct > behaviour? Actually, what it's doing is inserting the DEFAULT value for the field in question. If you don't specify a DEFAULT, it assumes null. # CREATE TABLE test_tbl (a integer, b text DEFAULT 'bbb', c text); # INSERT INTO test_tbl (a) VALUES (1); # SELECT * FROM test_tbl; a | b | c ---+-----+--- 1 | bbb | If you specify NOT NULL and don't want to provide a value you'll need to set a DEFAULT. -- Richard Huxton Archonet Ltd