Home > Archive > PostgreSQL Performance > March 2006 > limitation using LIKE on ANY(array)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author limitation using LIKE on ANY(array)
K C Lau

2006-03-24, 9:32 am


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

Indeed, I get rejected even with:
... WHERE ANY(array) = 'xx'

In both cases, the error is: ERROR: syntax error at or near "any" ...

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

It appears that this restriction is still in place in 8.2:
>http://developer.postgresql.org/doc...res/arrays.html


Is that the case?

Thanks in advance,
KC.
Tom Lane

2006-03-24, 11:42 am

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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

K C Lau

2006-03-24, 8:27 pm

Thank you very much, Tom. We'll try it and report if there is any
significant impact performance-wise.

Best regards,
KC.

At 00:25 06/03/25, Tom Lane wrote:
>K C Lau <kclau60@netvigator.com> writes:
>
>
>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.
>
>
>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



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com