Re: Re: BUG #4078: ERROR: operator does not exist: numeric = character varying

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eric Haszlakiewicz <erh(at)swapsimple(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: BUG #4078: ERROR: operator does not exist: numeric = character varying
Date: 2008-10-14 01:10:41
Message-ID: 1403.1223946641@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Eric Haszlakiewicz <erh(at)swapsimple(dot)com> writes:
> I created this, which seems to solve the problem:

> create function casting_eq_operator(integer, "char")
> returns boolean as 'begin
> return $1 = cast ($2 as integer);
> end;' language plpgsql immutable strict;

> CREATE OPERATOR = (PROCEDURE = casting_eq_operator,
> LEFTARG = integer , RIGHTARG = "char",
> COMMUTATOR = =, NEGATOR = !=, HASHES, MERGES
> );

> Can this be included by default?

No. Even if we desired to reverse the decision about not having
implicit casting behavior, this definition of the operator would not be
appropriate because it provides the opposite of the old behavior.
The pre-8.3 behavior would have been to cast the integer to text and
apply a textual comparison; which gives different comparison behavior,
eg leading zeroes in the string would affect the result. Not to mention
that the cast to integer in this definition would fail outright if the
string didn't look like an integer.

A large part of the reasoning for getting rid of the implicit casts
was exactly that it's not very clear what a comparison of this sort
should act like, and most people who are accidentally invoking it
haven't thought that through either.

(Some other problems: I'm pretty sure you meant to refer to text or
varchar not "char"; you referenced commutator and negator operators
without defining them; this operator certainly does not hash, and
I don't think it merges either, though maybe you could make the latter
work if you'd provided all the requisite btree-opfamily infrastructure.)

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert 'BoBsoN' Partyka 2008-10-14 14:10:38 BUG #4478: = operator in connection with CASE looks like loose some functionality (bug or feature?)
Previous Message fatih batuk 2008-10-13 08:24:03 initdb problem => creating template1 database in C:/Program Files/.. ... child process exited with exit code 1

Browse pgsql-general by date

  From Date Subject
Next Message justin 2008-10-14 01:40:55 Re: Chart of Accounts
Previous Message Daniel Browning 2008-10-14 00:47:31 Photos from PostgreSQL Conference West 2008