Re: BUG #4767: create operator - negator doesn't work

Lists: pgsql-bugs
From: "fduerr" <fduerr(at)gmx(dot)de>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4767: create operator - negator doesn't work
Date: 2009-04-21 11:04:01
Message-ID: 200904211104.n3LB419B076817@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4767
Logged by: fduerr
Email address: fduerr(at)gmx(dot)de
PostgreSQL version: 8.3.x 8.4.b1
Operating system: Debian Lenny
Description: create operator - negator doesn't work
Details:

Hi,
my apologies beforehand in case i'm just too stupid to understand the
documentation...
i understand, that the operator's negator argument specifies the operator
that, when applied with the same operands, yields the inverted result.
So thats what i did:

CREATE OR REPLACE FUNCTION eq_int_bool(INTEGER, BOOLEAN) RETURNS BOOLEAN AS
'SELECT CAST($1 AS BOOLEAN)=$2;' LANGUAGE SQL IMMUTABLE;
CREATE OPERATOR = (
LEFTARG=INTEGER,
RIGHTARG=BOOLEAN,
PROCEDURE=eq_int_bool,
COMMUTATOR= = ,
NEGATOR= <>
);

And thats, what i got:

SELECT 1=false;
?column?
----------
f
(1 row)

SELECT 1<>false;
8.3.x: ERROR: cache lookup failed for function 0
8.4b1: ERROR: operator is only a shell: integer <> boolean

The workaround is, of course, to define an operator with '<>' as commutator
that returns the negated result. Still i wonder: is it me, the documentation
or pg?


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Cc: "fduerr" <fduerr(at)gmx(dot)de>
Subject: Re: BUG #4767: create operator - negator doesn't work
Date: 2009-04-21 12:05:32
Message-ID: 200904211505.32682.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Tuesday 21 April 2009 14:04:01 fduerr wrote:
> CREATE OR REPLACE FUNCTION eq_int_bool(INTEGER, BOOLEAN) RETURNS BOOLEAN AS
> 'SELECT CAST($1 AS BOOLEAN)=$2;' LANGUAGE SQL IMMUTABLE;
> CREATE OPERATOR = (
> LEFTARG=INTEGER,
> RIGHTARG=BOOLEAN,
> PROCEDURE=eq_int_bool,
> COMMUTATOR= = ,
> NEGATOR= <>
> );
>
> And thats, what i got:
>
> SELECT 1=false;
> ?column?
> ----------
> f
> (1 row)
>
> SELECT 1<>false;
> 8.3.x: ERROR: cache lookup failed for function 0
> 8.4b1: ERROR: operator is only a shell: integer <> boolean
>
> The workaround is, of course, to define an operator with '<>' as commutator
> that returns the negated result. Still i wonder: is it me, the
> documentation or pg?

What you did above is to specify which operator is the negator of =. But you
still need to create that operator; it is not created automatically.