X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 00F6756406 for ; Wed, 2 Mar 2005 08:32:21 +0000 (GMT) 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 73824-01 for ; Wed, 2 Mar 2005 08:32:13 +0000 (GMT) Received: from mnc.ch (unknown [212.23.250.43]) by svr1.postgresql.org (Postfix) with ESMTP id 883EE563E4 for ; Wed, 2 Mar 2005 08:32:10 +0000 (GMT) Received: (qmail 22771 invoked from network); 2 Mar 2005 09:32:09 +0100 Received: from 62-2-77-204.business.cablecom.ch (HELO meuh.mnc.ch) (62.2.77.204) by www.mnc.ch.com with SMTP; 2 Mar 2005 09:32:09 +0100 Received: by meuh.mnc.ch (Postfix, from userid 1000) id E06D123F50B; Wed, 2 Mar 2005 09:32:06 +0100 (CET) To: Tom Lane Cc: pgsql-jdbc@postgresql.org Subject: Re: impossible to update rows specifying columns with NULL References: <87wtssj2c4.fsf@meuh.mnc.ch> <42237EFA.1060502@opencloud.com> <87fyzfzqgd.fsf@meuh.mnc.ch> <4224528A.3010606@opencloud.com> <422460E3.3040100@fastcrypt.com> <42247349.8030205@logi-track.com> <877jkrxxoa.fsf@meuh.mnc.ch> <19062.1109700228@sss.pgh.pa.us> From: Guillaume Cottenceau Date: 02 Mar 2005 09:32:06 +0100 In-Reply-To: <19062.1109700228@sss.pgh.pa.us> Message-ID: <87mztmv46x.fsf@meuh.mnc.ch> Lines: 45 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.052 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/16 X-Sequence-Number: 12409 Tom Lane writes: > Guillaume Cottenceau writes: > > Markus Schaber writes: > >> You don't have to do this globally, you can also issue > >> set transform_null_equals to true; > >> as statement so this setting is only for your connection. > > > In the doc pointed by Oliver I can read that this NULL != NULL > > behaviour is per SQL standard, so I'm unsure if I should go the > > way of forcing the non standard behaviour.. > > I don't think it will help you anyway. That kluge only deals with > the literal syntax "something = NULL" where the NULL is written out > as the keyword NULL. You appear to be wishing that "something = $n" > would be treated as "something IS NULL" if the parameter $n happened > to have the value NULL, and that most definitely isn't going to happen. > > A workaround in recent PG versions is to use "IS DISTINCT FROM", which > is a version of != that works the way you want with nulls. However this > is guaranteed not to be indexable so I don't know how useful it is in > real-world cases. > > In my mind, if you are up against this it suggests that you are misusing > NULL as a "real" data value, which is going to be a big headache given > the SQL sematics for NULL. You ought to rethink your data > representation. Thanks for your advices. Actually my "workaround" has been very logical: I use two different PreparedStatement. About data model, you may be right, I absolutely don't pretend to be any good in data modeling :). The table I'm dealing with represents a money balance, counted to send warnings to users when they reach configurable levels of expenses. The column that can be NULL represents a subset of locations where expenses can occur. We use non-NULL values when we want to count per-user and per-location, and NULL value when we want to count per-user but for all locations together. These two situations exist because of external constraints. -- Guillaume Cottenceau