pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Lars Erik Thorsplass <thorsplass@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Inserts with incomplete rows... NOT NULL constraints
Date: Wed, 11 Aug 2004 14:34:15 +0100
Message-ID: <411A2057.60109@archonet.com> (raw)
In-Reply-To: <7eeb33a040811053563894d7b@mail.gmail.com>
References: <7eeb33a040811053563894d7b@mail.gmail.com>

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



view thread (4+ messages)  latest in thread

Message-ID: <411A2057.60109@archonet.com>
Permalink:  ../411A2057.60109@archonet.com/
Also on:    postgresql.org/message-id/411A2057.60109@archonet.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: dev@archonet.com, thorsplass@gmail.com
  Subject: Re: Inserts with incomplete rows... NOT NULL constraints
  In-Reply-To: <411A2057.60109@archonet.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