Skip site navigation (1) Skip section navigation (2)

Re: Comparing arrays

From: A Gilmore <agilmore(at)shaw(dot)ca>
To: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Comparing arrays
Date: 2005-10-04 05:16:01
Message-ID: 43421011.7090000@shaw.ca (view raw or flat)
Thread:
Lists: pgsql-novice
Andreas Kretschmer wrote:
> A Gilmore <agilmore(at)shaw(dot)ca> schrieb:
> 
> 
>>Hello,
>>
>>Id like to compare two arrays, and if any value is found in both, return 
>>true.  Is this possible without needing a procedure to loop through one?
>>
>>For example, say categories is an array :
>>
>>SELECT * FROM t1 WHERE ANY(ARRAY[5,7,9]) = ANY(categories);
> 
> 
> Nice question. I have written a little function. You can see this on
> http://a-kretschmer.de/tools/array_compare.sql.
> Let me know if you have a better solution.
> 
> 
> Regards, Andreas

Thank you for the reference, the use of array_upper() is quite useful. 
Apparently there is no straight-forward way to do it in SQL, so I ended 
up writing a similiar plpgsql function.

- A Gilmore

In response to

pgsql-novice by date

Next:From: Andrew BorleyDate: 2005-10-04 10:56:54
Subject: grant select on all tables
Previous:From: operationsengineer1Date: 2005-10-03 23:02:20
Subject: Re: Trouble Connecting to DB After PGAdmin3 1.2.2 pgsql 7.4.5 Backup and 8.03 Restore - SOLVED w/ QUESTION

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group