Re: Converting string to IN query

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: Converting string to IN query
Дата
Msg-id 20080912155745.GE7271@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на Re: Converting string to IN query  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
On Fri, Sep 12, 2008 at 04:04:18PM +0100, Richard Huxton wrote:
> Andrus wrote:
> > String contains list of document numbers (integers) like:
> >
> > '1,3,4'
> >
> > How to SELECT documents whose numbers are contained in this string.
>
> > Numbers should be passed as single string literal since FYIReporting
> > RDLEngine does not allow multivalue parameters.
>
> Hmm - might be worth bringing that to their attention.

I'm probably missing something, but does PG?

> Try string_to_array(). Example:
>
> SELECT * FROM generate_series(1,10) s
> WHERE s = ANY (string_to_array('1,3,5,7', ',')::int[]);

I don't think you need the string_to_array function call, an array
literal should do perfectly well here.  I.e.

  WHERE s = ANY ('{1,2,3}'::int[]);

the literal can of course be a parameter as well:

  WHERE s = ANY ($1::int[]);


  Sam

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

Предыдущее
От: "Dmitry Koterov"
Дата:
Сообщение: TSearch2: find a QUERY that does match a single document
Следующее
От: William Garrison
Дата:
Сообщение: Fastest way to restore a database