Re: Selecting values from comma separated string

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Selecting values from comma separated string
Date: 2009-08-26 14:05:08
Message-ID: 11645.1251295508@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> writes:
> In response to Nacef LABIDI :
>> I want to write a function that takes as param a comma separated values string
>> and perform a select matching these values.

> Use EXECUTE sql_string,

Safer to use string_to_array, for instance

... WHERE id = ANY(string_to_array('1,3,7,8', ',')::int[]) ...

Of course this just begs the question of why the OP doesn't use an
array in the first place.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nacef LABIDI 2009-08-26 14:13:39 Re: Selecting values from comma separated string
Previous Message Pavel Stehule 2009-08-26 13:33:11 Re: Selecting values from comma separated string