Re: problems with array - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: problems with array
Date
Msg-id 20051019033544.GA66012@winnie.fuhr.org
Whole thread Raw
In response to Re: problems with array  (Matthew Peter <survivedsushi@yahoo.com>)
Responses Re: problems with array  (Matthew Peter <survivedsushi@yahoo.com>)
List pgsql-sql
On Tue, Oct 18, 2005 at 08:09:48PM -0700, Matthew Peter wrote:
> Not sure if you got this figured out but I think
> 
> SELECT * from tb_cat WHERE id IN (SELECT
> array_to_string(cat,',') as cat FROM tb_array WHERE
> id=1);
> 
> is what your looking for?

I doubt it, considering that it doesn't work :-(

SELECT * from tb_cat WHERE id IN (SELECT
array_to_string(cat,',') as cat FROM tb_array WHERE
id=1);
id | desc 
----+------
(0 rows)

This might do the trick:

SELECT c.*
FROM tb_cat AS c, tb_array AS a
WHERE c.id = ANY (a.cat) AND a.id = 1;
id | desc  
----+-------10 | cat1020 | cat20
(2 rows)

Or if you prefer the explicit join syntax:

SELECT c.*
FROM tb_cat AS c JOIN tb_array AS a ON c.id = ANY (a.cat)
WHERE a.id = 1;
id | desc  
----+-------10 | cat1020 | cat20
(2 rows)

-- 
Michael Fuhr


pgsql-sql by date:

Previous
From: Matthew Peter
Date:
Subject: Re: problems with array
Next
From: Michael Glaesemann
Date:
Subject: Re: Problem -Postgre sql