Re: Shouldn't "WHEN (OLD.* IS DISTINCT FROM NEW.*)" clause be independent from data type?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, "pinker *EXTERN*" <pinker(at)onet(dot)eu>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Shouldn't "WHEN (OLD.* IS DISTINCT FROM NEW.*)" clause be independent from data type?
Date: 2015-09-17 13:56:22
Message-ID: CAKFQuwYGAUzF7T=ENnn2oPNTRaZxkQvyPDvVVWtBiba84zxDqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Sep 17, 2015 at 9:39 AM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 09/17/2015 06:32 AM, Albe Laurenz wrote:
>
>> pinker wrote:
>>
>>> I've tried to write audit trigger which fires only when data changed, so
>>> I used "WHEN (OLD.* IS
>>> DISTINCT FROM NEW.*)" clause as described in documentation
>>> <http://www.postgresql.org/docs/9.4/static/sql-createtrigger.html> .
>>> Should this clause be independent
>>> from data type? because an error occurs when I'm trying to modify row
>>> with point data type: ERROR:
>>> could not identify an equality operator for type point
>>>
>>
>> I guess it is dependent on data type as it requires an equality operator,
>> and type "point" doesn't have one.
>>
>
> To echo the OP, why is that?
>
> http://www.postgresql.org/docs/9.4/interactive/functions-comparison.html
>
> For non-null inputs, IS DISTINCT FROM is the same as the <> operator.
>
> So:
>
> test=> select '(1,2)'::point <> '(1,2)'::point;
> ?column?
> ----------
> f
> (1 row)
>
> test=> select '(1,2)'::point <> '(1,3)'::point;
> ?column?
> ----------
> t
>
> test=> select '(1,2)'::point <> null;
> ?column?
> ----------
>
> (1 row)
>
>
​SELECT not ('(0,4)'::point = '(1,2)'::point)

ERROR: operator does not exist: point = point

If it calling it a bug gets it changed I'm game...but IS DISTINCT FROM
apparently looks for an equality operator and then performs negation
instead of looking for a "non-equality" operator. Since the latter doesn't
really even make sense (TBH it's probably syntatic sugar transformed by the
parser) I don't blame it.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2015-09-17 14:14:47 Re: Shouldn't "WHEN (OLD.* IS DISTINCT FROM NEW.*)" clause be independent from data type?
Previous Message Tom Lane 2015-09-17 13:54:35 Re: Shouldn't "WHEN (OLD.* IS DISTINCT FROM NEW.*)" clause be independent from data type?