Re: using a list to query

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: using a list to query
Дата
Msg-id 49FCF4C1.8020701@postnewspapers.com.au
обсуждение исходный текст
Ответ на using a list to query  (johnf <jfabiani@yolo.com>)
Ответы Re: using a list to query
Список pgsql-sql
johnf wrote:
> I have a list (or array) of primary keys stored in a field (data type text).  
> I would like to use the list to retrieve all the data from a table based on 
> the list.
> 
> my text field contains:
>  '123,134,343,345'
> 
> I would to do something like the following:
> 
> Select * from table1 where table1.pkid in (select myTextfield from table2)
> 
> So the question is there a simple way to use the list to retrieve my data?

http://www.postgresql.org/docs/8.3/static/functions-matching.html

SELECT * FROM table1
WHERE table1.pkid IN ( SELECT x FROM regexp_split_to_table(myTextfield, ',') AS x
);

... but you should consider storing your list in an array instead, or
using a more conventional child table with a (pkid, refid) pair list.

--
Craig Ringer


В списке pgsql-sql по дате отправления:

Предыдущее
От: Lucas Brito
Дата:
Сообщение: Re: Comparing two tables of different database
Следующее
От: Isaac Dover
Дата:
Сообщение: Re: Comparing two tables of different database