Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VrEFU-0004Tz-IY for pgsql-sql@arkaria.postgresql.org; Thu, 12 Dec 2013 21:56:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VrEFU-0004tu-13 for pgsql-sql@arkaria.postgresql.org; Thu, 12 Dec 2013 21:56:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VrEFT-0004to-7d for pgsql-sql@postgresql.org; Thu, 12 Dec 2013 21:56:47 +0000 Received: from mail.mailpen.net ([209.59.217.159]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VrEFH-00047J-DQ for pgsql-sql@postgresql.org; Thu, 12 Dec 2013 21:56:45 +0000 Received: from [172.20.4.200] (50-46-168-128.evrt.wa.frontiernet.net [50.46.168.128]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mailpen.net (Postfix) with ESMTP id 9FBF51140B6 for ; Thu, 12 Dec 2013 13:56:32 -0800 (PST) Message-ID: <52AA3156.20902@ultimeth.com> Date: Thu, 12 Dec 2013 13:57:42 -0800 From: "Dean Gibson (DB Administrator)" Organization: UltiMeth Systems User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: NULLs and composite types References: <52A9010D.3070202@ultimeth.com> <1386876331115-5783187.post@n5.nabble.com> In-Reply-To: <1386876331115-5783187.post@n5.nabble.com> Content-Type: multipart/alternative; boundary="------------060409020107090008010004" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------060409020107090008010004 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2013-12-12 11:25, David Johnston wrote: > Dean Gibson (DB Administrator)-2 wrote >> What's going on? I can provide more detail if requested. Of course, an >> obvious workaround is to use in a VIEW: >> >> ... NULLIF( location, ROW( NULL, NULL )::"GeoPosition" ) ... >> >> but I'd like to know the cause. > Cannot test right now but the core issue is that IS NULL on a record type > evaluates both the scalar whole and the sub-components. Try using IS [NOT] > DISTINCT FROM with various target expressions and see if you can get > something more sane. > > David J. Yes, "SELECT ROW( NULL, NULL ) IS NULL;" produces TRUE, and "SELECT ROW( NULL, NULL ) IS NOT DISTINCT FROM NULL;" produces FALSE. However, my problem is not that the comparison tests produce different results; that's just a symptom. My problem is that PostgreSQL is *changing* a NULL record value, to a record with NULLs for the component values, when I attempt to INSERT or UPDATE it into a different field. That means in php (for example), that retrieving what started out as a NULL record (and in php retrieves an empty string), becomes a record with NULL values (and in php retrieves a "(,)" string). Yes, I can test for that in php, but problems/work-arounds need to be solved in the component that causes them. However, I have found a satisfactory work-around in the TRIGGER function to the problem: In my INSERT and UPDATE statements, I use: ... NULLIF( record_row.location, ROW( NULL, NULL )::"GeoPosition" ) ... when adding or changing a value. Note that setting "record_row.location" to NULL in PL/pgSQL just before the INSERT or UPDATE *does not solve the problem*, and tests of the value before and after setting the value in a record field (retrieved via a CURSOR FOR SELECT ...) shows that the value does not change to fully NULL. -- Mail to my list address MUST be sent via the mailing list. All other mail to my list address will bounce. --------------060409020107090008010004 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 2013-12-12 11:25, David Johnston wrote:
Dean Gibson (DB Administrator)-2 wrote
What's going on?  I can provide more detail if requested.  Of course, an 
obvious workaround is to use in a VIEW:

... NULLIF( location, ROW( NULL, NULL )::"GeoPosition" ) ...

but I'd like to know the cause.
Cannot test right now but the core issue is that IS NULL on a record type
evaluates both the scalar whole and the sub-components.  Try using IS [NOT]
DISTINCT FROM with various target expressions and see if you can get
something more sane.

David J.

Yes, "SELECT ROW( NULL, NULL ) IS NULL;" produces TRUE, and "SELECT ROW( NULL, NULL ) IS NOT DISTINCT FROM NULL;" produces FALSE.

However, my problem is not that the comparison tests produce different results;  that's just a symptom.  My problem is that PostgreSQL is changing a NULL record value, to a record with NULLs for the component values, when I attempt to INSERT or UPDATE it into a different field.  That means in php (for example), that retrieving what started out as a NULL record (and in php retrieves an empty string), becomes a record with NULL values (and in php retrieves a "(,)" string).  Yes, I can test for that in php, but problems/work-arounds need to be solved in the component that causes them.

However, I have found a satisfactory work-around in the TRIGGER function to the problem:  In my INSERT and UPDATE statements, I use:

... NULLIF( record_row.location, ROW( NULL, NULL )::"GeoPosition" ) ...

when adding or changing a value.

Note that setting "record_row.location" to NULL in PL/pgSQL just before the INSERT or UPDATE does not solve the problem, and tests of the value before and after setting the value in a record field (retrieved via a CURSOR FOR SELECT ...) shows that the value does not change to fully NULL.


-- 
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.
--------------060409020107090008010004--