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 2A8ADD1B510 for ; Wed, 19 Nov 2003 20:39:42 +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 62531-03 for ; Wed, 19 Nov 2003 16:39:12 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id C8CA1D1B50C for ; Wed, 19 Nov 2003 16:39:08 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id A5C7E35499; Wed, 19 Nov 2003 12:39:09 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A490235498; Wed, 19 Nov 2003 12:39:09 -0800 (PST) Date: Wed, 19 Nov 2003 12:39:09 -0800 (PST) From: Stephan Szabo To: Tomasz Spyrczak Cc: pgsql-admin@postgresql.org Subject: Re: Automatic null values convertion in INSERT and WHERE In-Reply-To: Message-ID: <20031119115602.F91425@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/362 X-Sequence-Number: 11349 On Wed, 19 Nov 2003, Tomasz Spyrczak wrote: > I've just compiled PostgreSQL 7.4 and come across this problem: > > I have a table like this: > > CREATE TABLE test (field1 integer, field2 integer default 0); > > 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. That's probably because in versions before 7.3 (IIRC the version it changed on) an empty string was treated as 0 when converted to an integer. This was considered inconsistent and removed. I don't believe that a GUC option was added to change this behavior (or at least I don't see it). > Similarily I want PostgreSQL to accept and automatically convert to "IS > NULL" "where" statements like this: > > SELECT * FROM test WHERE field1=''; > > I suppose this behavior can be change at the compile-time, but how please > tell me :-( Apart from making a view that has field1 as a textual type which converts NULLs into empty strings, I think you'd have to do actual source editing.