X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2FCEAD1B50A for ; Wed, 19 Nov 2003 19:29:21 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 47462-02 for ; Wed, 19 Nov 2003 15:28:51 -0400 (AST) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id B9801D1C95A for ; Wed, 19 Nov 2003 15:28:48 -0400 (AST) Received: (qmail 23279 invoked by uid 500); 19 Nov 2003 19:27:35 -0000 Date: Wed, 19 Nov 2003 13:27:35 -0600 From: Bruno Wolff III To: Tomasz Spyrczak Cc: pgsql-admin@postgresql.org Subject: Re: Automatic null values convertion in INSERT and WHERE statements Message-ID: <20031119192735.GB22998@wolff.to> Mail-Followup-To: Tomasz Spyrczak , pgsql-admin@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/359 X-Sequence-Number: 11346 On Wed, Nov 19, 2003 at 11:00:25 +0100, Tomasz Spyrczak wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Then I want to insert some "empty" record like this: > > INSERT INTO test (field1, field2) VALUES ('', ''); > > My question is: how to "convince" PostgreSQL to automatically convert (as it > is mentioned in the documentation) the given empty values to the default > values of field1 (to insert null value) and field2 (to insert default value > of 0)? After default compilation PostgreSQL 7.4 gives an error while doing > an insert query like this. > > Currently I am using pre-compiled PostgreSQL 7.2 from Linux Mandrake 9 and > such an insert query described above works as desired - it inserts into a > table default or null values without an error. Most likely it is inserting 0 which may just happen to be the default value. > How can I make PostgreSQL 7.4 to behave like that? You can use the keyword DEFAULT to insert the default value or NULL to insert a null value. > Similarily I want PostgreSQL to accept and automatically convert to "IS > NULL" "where" statements like this: > > SELECT * FROM test WHERE field1=''; There is a GUC flag you can change to get = NULL replaced by IS NULL, but there is nothing in postgres than will cause a comparison against an empty string to be the same as IS NULL. If you have controll over the SQL you should switch to using standard SQL.