Re: Differences in WHERE clause of SELECT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Prabakaran, Vaishnavi" <vaishnavip(at)fast(dot)au(dot)fujitsu(dot)com>
Cc: Kevin Grittner <kgrittn(at)ymail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Differences in WHERE clause of SELECT
Date: 2013-07-19 02:35:43
Message-ID: 2612.1374201343@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Prabakaran, Vaishnavi" <vaishnavip(at)fast(dot)au(dot)fujitsu(dot)com> writes:
> The specific use case which I am interested in is

> " Numeric LIKE Pattern_string ".

> I'm willing to attempt a patch to support the specific use case above by adding implicit casts, without modifying the entire casting rules.

> Is this something that is likely to be included in the code ?

No, especially not if you do it by adding implicit casts. That would
have unfortunate side-effects in all sorts of contexts.

If you're dead set on having this sort of behavior, you can do it today
with a custom operator, for instance:

regression=# select 1.4 like 'foo';
ERROR: operator does not exist: numeric ~~ unknown
LINE 1: select 1.4 like 'foo';
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
regression=# create function numericlike(numeric, text) returns bool as
regression-# 'select $1::text like $2' language sql;
CREATE FUNCTION
regression=# create operator ~~ (leftarg = numeric, rightarg = text,
regression(# procedure = numericlike);
CREATE OPERATOR
regression=# select 1.4 like 'foo';
?column?
----------
f
(1 row)

I'd suggest doing that rather than making changes that are likely to
have side-effects on behavior entirely unrelated to LIKE. In addition,
you won't have to sell the community on whether this behavior is
actually a good idea.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2013-07-19 02:37:18 AGG_PLAIN thinks sorts are free
Previous Message Prabakaran, Vaishnavi 2013-07-19 02:21:40 Re: Differences in WHERE clause of SELECT