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

From: Richard Broersma <richard(dot)broersma(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:01
Message-ID: AANLkTim9K8g6uCEYU95BU2zAZZSUmMr3+Xi96wxsyGYi@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Oct 25, 2010 at 9:07 AM, Axel Rau <Axel(dot)Rau(at)chaos1(dot)de> wrote:

> 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 );

Here is what I think should work:

UPDATE foo
Set x = y
WHERE id = ANY( CAST( string_to_array( '1,2,3,4', ',' ) AS INTEGER[] ));

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Sergey Konoplev 2010-10-25 16:17:55 Re: Using PL/pgSQL text argument in 'IN (INT, INT, ...)' clause [re-post]
Previous Message Axel Rau 2010-10-25 16:07:51 Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause [re-post]