X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1941F9DC841 for ; Fri, 24 Mar 2006 12:26:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68325-08 for ; Fri, 24 Mar 2006 12:26:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D94F49DC84D for ; Fri, 24 Mar 2006 12:26:00 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k2OGPtIs005276; Fri, 24 Mar 2006 11:25:55 -0500 (EST) To: K C Lau cc: pgsql-performance@postgresql.org Subject: Re: limitation using LIKE on ANY(array) 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> Comments: In-reply-to K C Lau message dated "Fri, 24 Mar 2006 23:25:00 +0800" Date: Fri, 24 Mar 2006 11:25:55 -0500 Message-ID: <5275.1143217555@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.252 required=5 tests=[AWL=-0.024, MAILTO_TO_SPAM_ADDR=0.276] X-Spam-Score: 0.252 X-Spam-Level: X-Archive-Number: 200603/503 X-Sequence-Number: 17940 K C Lau 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