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 40EF9563FE for ; Mon, 7 Mar 2005 08:59:35 +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 76049-02 for ; Mon, 7 Mar 2005 08:59:31 +0000 (GMT) Received: from mail.osp-dd.de (mail.osp-dd.de [213.70.173.134]) by svr1.postgresql.org (Postfix) with ESMTP id 20B71563C0 for ; Mon, 7 Mar 2005 08:59:22 +0000 (GMT) Received: (from root@localhost) by mail.osp-dd.de (8.12.10/8.12.10/???) id j278xKxN008921 for pgsql-jdbc@postgresql.org; Mon, 7 Mar 2005 09:59:21 +0100 Received: from kolab.osp-dd.de ([172.29.100.44]) by mail.osp-dd.de (8.12.10/8.12.10/???) with ESMTP id j278x7Ik008718 for ; Mon, 7 Mar 2005 09:59:08 +0100 Received: from localhost (localhost [127.0.0.1]) by kolab.osp-dd.de (Postfix) with ESMTP id D79F11454004 for ; Mon, 7 Mar 2005 09:59:07 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by kolab.osp-dd.de (Postfix) with ESMTP id B49711454003; Mon, 7 Mar 2005 09:59:07 +0100 (CET) Received: from kolab.osp-dd.de ([127.0.0.1]) by localhost (kolab [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20781-07; Mon, 7 Mar 2005 09:59:07 +0100 (CET) Received: from kubis.osp-dd.de (kubis.osp-dd.de [172.29.100.154]) by kolab.osp-dd.de (Postfix) with ESMTP id 2AD0B1454001; Mon, 7 Mar 2005 09:59:07 +0100 (CET) Received: (from ulbrich@localhost) by kubis.osp-dd.de (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) id j278x6d29087; Mon, 7 Mar 2005 09:59:06 +0100 Date: Mon, 7 Mar 2005 09:59:06 +0100 From: Andreas Ulbrich To: Guillaume Cottenceau Cc: pgsql-jdbc@postgresql.org Subject: Re: impossible to update rows specifying columns with NULL Message-ID: <20050307095906.A28847@kubis.osp-dd.de> 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> <87mztmv46x.fsf@meuh.mnc.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.16i In-Reply-To: <87mztmv46x.fsf@meuh.mnc.ch>; from gc@mnc.ch on Wed, Mar 02, 2005 at 09:32:06AM +0100 X-Virus-Scanned: by amavisd-new at osp-dd.de X-Kolab-Scheduling-Message: FALSE X-scanner: scanned by Inflex 1.0.12.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/38 X-Sequence-Number: 12431 I found in our project the following construct to handle this situation: UPDATE tab SET colx = ... WHERE ... coly IS NULL AND ? IS NULL OR coly = ? ... - You must bind the value twice. - We are using ORACLE, but it seems to bo standard like Andreas On Wed, Mar 02, 2005 at 09:32:06AM +0100, Guillaume Cottenceau wrote: > 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 -- Andreas Ulbrich Otto Software Partner GmbH Freiberger Str. 35; D-01067 Dresden Tel.: [[0[049]351]49723]20