pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
WHERE 'Something%' LIKE ANY (array_field)
5+ messages / 4 participants
[nested] [flat]

* WHERE 'Something%' LIKE ANY (array_field)
@ 2013-08-14 09:44  Tim Kane <tim.kane@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tim Kane @ 2013-08-14 09:44 UTC (permalink / raw)
  To: pgsql-general

Hi all,

It seems like it isn't possible to perform a wildcard LIKE evaluation
against array objects. Is this a bug, or just unsupported?


See the queries in bold, that I would have expected to return a value.
Postgres 9.1.9


=# create temp table ids (id varchar(12)[]);
CREATE TABLE
Time: 185.516 ms
=# insert into ids values ('{s1,s452334,s89}');
INSERT 0 1
Time: 0.728 ms
=# insert into ids values ('{s89}');
INSERT 0 1
Time: 0.300 ms
=# insert into ids values ('{s9323,s893}');
INSERT 0 1
Time: 0.133 ms
=# insert into ids values ('{s9323,s893,s89}');
INSERT 0 1
Time: 0.110 ms
=# select * from ids;
        id
------------------
 {s1,s452334,s89}
 {s89}
 {s9323,s893}
 {s9323,s893,s89}
(4 rows)

Time: 0.155 ms
=# select * from ids where 's89' = ANY (id);
        id
------------------
 {s1,s452334,s89}
 {s89}
 {s9323,s893,s89}
(3 rows)

Time: 0.121 ms
*clone=# select * from ids where 's45%' LIKE ANY (id);*
 id
----
(0 rows)

Time: 0.124 ms

*clone=# select * from ids where 's452334%' LIKE ANY (id);*
 id
----
(0 rows)

Time: 0.278 ms
clone=# select * from ids where 's452334' LIKE ANY (id);
        id
------------------
 {s1,s452334,s89}
(1 row)

Time: 0.134 ms
clone=# select * from ids where 's452334' = ANY (id);
        id
------------------
 {s1,s452334,s89}
(1 row)

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: WHERE 'Something%' LIKE ANY (array_field)
@ 2013-08-14 09:55  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Tim Kane <tim.kane@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Pavel Stehule @ 2013-08-14 09:55 UTC (permalink / raw)
  To: Tim Kane <tim.kane@gmail.com>; +Cc: pgsql-general

Hello

http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#LIKE_to_list_of_patterns

Regards

Pavel Stehule


2013/8/14 Tim Kane <tim.kane@gmail.com>

> Hi all,
>
> It seems like it isn't possible to perform a wildcard LIKE evaluation
> against array objects. Is this a bug, or just unsupported?
>
>
> See the queries in bold, that I would have expected to return a value.
> Postgres 9.1.9
>
>
> =# create temp table ids (id varchar(12)[]);
> CREATE TABLE
> Time: 185.516 ms
> =# insert into ids values ('{s1,s452334,s89}');
> INSERT 0 1
> Time: 0.728 ms
> =# insert into ids values ('{s89}');
> INSERT 0 1
> Time: 0.300 ms
> =# insert into ids values ('{s9323,s893}');
> INSERT 0 1
> Time: 0.133 ms
> =# insert into ids values ('{s9323,s893,s89}');
> INSERT 0 1
> Time: 0.110 ms
> =# select * from ids;
>         id
> ------------------
>  {s1,s452334,s89}
>  {s89}
>  {s9323,s893}
>  {s9323,s893,s89}
> (4 rows)
>
> Time: 0.155 ms
> =# select * from ids where 's89' = ANY (id);
>         id
> ------------------
>  {s1,s452334,s89}
>  {s89}
>  {s9323,s893,s89}
> (3 rows)
>
> Time: 0.121 ms
> *clone=# select * from ids where 's45%' LIKE ANY (id);*
>  id
> ----
> (0 rows)
>
> Time: 0.124 ms
>
> *clone=# select * from ids where 's452334%' LIKE ANY (id);*
>  id
> ----
> (0 rows)
>
> Time: 0.278 ms
> clone=# select * from ids where 's452334' LIKE ANY (id);
>         id
> ------------------
>  {s1,s452334,s89}
> (1 row)
>
> Time: 0.134 ms
> clone=# select * from ids where 's452334' = ANY (id);
>         id
> ------------------
>  {s1,s452334,s89}
> (1 row)
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: WHERE 'Something%' LIKE ANY (array_field)
@ 2013-08-14 18:01  Tim Kane <tim.kane@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tim Kane @ 2013-08-14 18:01 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-general

Thanks Pavel,

Unless I'm being bleary eyed and not quite grasping it...  I'm not sure
that answers my question.
I'm using a single LIKE clause against an array parameter, rather than
multiple LIKE clauses against a single parameter.


It seems I'm so far stuck with a FOREACH style traversal within plpgsql
(which is fine, as this is all to be used within a function anyway).




On Wed, Aug 14, 2013 at 10:55 AM, Pavel Stehule <pavel.stehule@gmail.com>wrote:

> Hello
>
> http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#LIKE_to_list_of_patterns
>
> Regards
>
> Pavel Stehule
>
>
> 2013/8/14 Tim Kane <tim.kane@gmail.com>
>
>> Hi all,
>>
>> It seems like it isn't possible to perform a wildcard LIKE evaluation
>> against array objects. Is this a bug, or just unsupported?
>>
>>
>> See the queries in bold, that I would have expected to return a value.
>> Postgres 9.1.9
>>
>>
>> =# create temp table ids (id varchar(12)[]);
>> CREATE TABLE
>> Time: 185.516 ms
>> =# insert into ids values ('{s1,s452334,s89}');
>> INSERT 0 1
>> Time: 0.728 ms
>> =# insert into ids values ('{s89}');
>> INSERT 0 1
>> Time: 0.300 ms
>> =# insert into ids values ('{s9323,s893}');
>> INSERT 0 1
>> Time: 0.133 ms
>> =# insert into ids values ('{s9323,s893,s89}');
>> INSERT 0 1
>> Time: 0.110 ms
>> =# select * from ids;
>>         id
>> ------------------
>>  {s1,s452334,s89}
>>  {s89}
>>  {s9323,s893}
>>  {s9323,s893,s89}
>> (4 rows)
>>
>> Time: 0.155 ms
>> =# select * from ids where 's89' = ANY (id);
>>         id
>> ------------------
>>  {s1,s452334,s89}
>>  {s89}
>>  {s9323,s893,s89}
>> (3 rows)
>>
>> Time: 0.121 ms
>> *clone=# select * from ids where 's45%' LIKE ANY (id);*
>>  id
>> ----
>> (0 rows)
>>
>> Time: 0.124 ms
>>
>> *clone=# select * from ids where 's452334%' LIKE ANY (id);*
>>  id
>> ----
>> (0 rows)
>>
>> Time: 0.278 ms
>> clone=# select * from ids where 's452334' LIKE ANY (id);
>>         id
>> ------------------
>>  {s1,s452334,s89}
>> (1 row)
>>
>> Time: 0.134 ms
>> clone=# select * from ids where 's452334' = ANY (id);
>>         id
>> ------------------
>>  {s1,s452334,s89}
>> (1 row)
>>
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: WHERE 'Something%' LIKE ANY (array_field)
@ 2013-08-14 18:23  Kevin Grittner <kgrittn@ymail.com>
  parent: Tim Kane <tim.kane@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Kevin Grittner @ 2013-08-14 18:23 UTC (permalink / raw)
  To: Tim Kane <tim.kane@gmail.com>; Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-general

Tim Kane <tim.kane@gmail.com> wrote:

> I'm using a single LIKE clause against an array parameter, rather
> than multiple LIKE clauses against a single parameter.

The problem is that you have the arguments to the LIKE parameter
reversed with the attempts you show.  Try something like this:

select * from ids
  where exists
   (select * from (select unnest(ids.id)) x(id)
                     where x.id like 's45%');

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: WHERE 'Something%' LIKE ANY (array_field)
@ 2018-03-07 12:51  Vishal <vishalvamrutiya@gmail.com>
  parent: Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Vishal @ 2018-03-07 12:51 UTC (permalink / raw)
  To: pgsql-general

Thank it is working in my senario



--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2018-03-07 12:51 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-08-14 09:44 WHERE 'Something%' LIKE ANY (array_field) Tim Kane <tim.kane@gmail.com>
2013-08-14 09:55 ` Pavel Stehule <pavel.stehule@gmail.com>
2013-08-14 18:01   ` Tim Kane <tim.kane@gmail.com>
2013-08-14 18:23     ` Kevin Grittner <kgrittn@ymail.com>
2018-03-07 12:51       ` Vishal <vishalvamrutiya@gmail.com>

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