Re: Selecting values from comma separated string

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Nacef LABIDI <nacef(dot)l(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Selecting values from comma separated string
Date: 2009-08-26 13:32:02
Message-ID: 162867790908260632o685077a7xc125871fd1f6149@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

postgres=# select * from foo;
+---+---+
| i | a |
+---+---+
| 1 | a |
| 2 | b |
| 3 | c |
+---+---+
(3 rows)

Time: 0,654 ms
postgres=# select * from foo where i = ANY (string_to_array('1,3',',')::int[]);
+---+---+
| i | a |
+---+---+
| 1 | a |
| 3 | c |
+---+---+
(2 rows)

Time: 0,914 ms

regards
Pavel Stehule

2009/8/26 Nacef LABIDI <nacef(dot)l(at)gmail(dot)com>:
> Hi all,
>
> I want to write a function that takes as param a comma separated values
> string and perform a select matching these values.
>
> Here is the string '1,3,7,8'
>
> And I wan to perform a : SELECT * FROM my_table WHERE id IN (1, 3, 7, 8);
>
> Does anyone have a clue ?
>
> Thanks
>
> Nacef
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Pavel Stehule 2009-08-26 13:33:11 Re: Selecting values from comma separated string
Previous Message A. Kretschmer 2009-08-26 13:30:36 Re: Selecting values from comma separated string