pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: K C Lau <kclau60@netvigator.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: limitation using LIKE on ANY(array)
Date: Fri, 24 Mar 2006 11:25:55 -0500
Message-ID: <5275.1143217555@sss.pgh.pa.us> (raw)
In-Reply-To: <6.2.1.2.0.20060324225743.04d49ac0@localhost>
References: <200603170625.k2H6PJ926955@pillette.com>
	<1143112188.2810.27.camel@theo-laptop.int.coza.net.za>
	<20060323132448.GB4881@surnet.cl>
	<4423E90E.2090607@rentalia.com>
	<20060324125245.GB90527@pervasive.com>
	<4423EDA9.3090502@rentalia.com>
	<20060324130619.GF90527@pervasive.com>
	<20060324133252.GA22688@winnie.fuhr.org>
	<6.2.1.2.0.20060324225743.04d49ac0@localhost>

K C Lau <kclau60@netvigator.com> writes:
> Indeed, I get rejected even with:
> .. WHERE ANY(array) = 'xx'

> It would only work as documented in the manual (8.10.5):
> SELECT * FROM sal_emp WHERE 10000 = ANY (pay_by_quarter);

That's not changing any time soon; the SQL spec defines only the second
syntax for ANY, and I believe there would be syntactic ambiguity if we
tried to allow the other.

> With 8.1.3, I get an error when trying to do this on a Text[] column :
> .. WHERE ANY(array) LIKE 'xx%'

If you're really intent on doing that, make an operator for "reverse
LIKE" and use it with the ANY on the right-hand side.

regression=# create function rlike(text,text) returns bool as
regression-# 'select $2 like $1' language sql strict immutable;
CREATE FUNCTION
regression=# create operator ~~~ (procedure = rlike, leftarg = text,
regression(# rightarg = text, commutator = ~~);
CREATE OPERATOR
regression=# select 'xx%' ~~~ any(array['aaa','bbb']);
 ?column?
----------
 f
(1 row)

regression=# select 'xx%' ~~~ any(array['aaa','xxb']);
 ?column?
----------
 t
(1 row)

regression=#

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <5275.1143217555@sss.pgh.pa.us>
Permalink:  ../5275.1143217555@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5275.1143217555@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kclau60@netvigator.com
  Subject: Re: limitation using LIKE on ANY(array)
  In-Reply-To: <5275.1143217555@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox