Re: Using PL/pgSQL text argument in 'IN (INT, INT, ...)' clause [re-post]

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Axel Rau <Axel(dot)Rau(at)chaos1(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using PL/pgSQL text argument in 'IN (INT, INT, ...)' clause [re-post]
Date: 2010-10-25 16:17:55
Message-ID: AANLkTi=P6n6msmU0dLEKD+G9YtWTDW_w_YGmNKRA0qEO@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

You can do this:

UPDATE foo SET x = y WHERE id = ANY(string_to_array(blah, ',')::integer[]);

Note that you need to cast string_to_array(...) to array type of your id type.

On 25 October 2010 20:07, Axel Rau <Axel(dot)Rau(at)chaos1(dot)de> wrote:
> Good morning,
>
> I have a function argument blah of type text containing something like
>   33,44,55,66
> . Can I cast it in some way to use it in an IN clause as integers like
>   UPDATE foo SET x = y WHERE id IN ( blah );
> or need I revert to dynamic SQL (EXECUTE...) ?
>
> Thanks, Axel
> ---
> axel(dot)rau(at)chaos1(dot)de  PGP-Key:29E99DD6  +49 151 2300 9283  computing @ chaos
> claudius
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

--
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray(dot)ru(at)gmail(dot)com / Skype: gray-hemp / ICQ: 29353802

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Axel Rau 2010-10-25 19:01:40 Re: Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause [re-post]
Previous Message Richard Broersma 2010-10-25 16:17:01 Re: Using PL/pgSQL text argument in 'IN (INT, INT, ...)' clause [re-post]