From: Pavel Stehule <pavel.stehule@gmail.com>
To: Nacef LABIDI <nacef.l@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Selecting values from comma separated string
Date: Wed, 26 Aug 2009 15:32:02 +0200
Message-ID: <162867790908260632o685077a7xc125871fd1f6149@mail.gmail.com> (raw)
In-Reply-To: <f16f7ea00908260619t59555d37u66bebfe47132304f@mail.gmail.com>
References: <f16f7ea00908260619t59555d37u66bebfe47132304f@mail.gmail.com>
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.l@gmail.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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pavel.stehule@gmail.com, nacef.l@gmail.com
Subject: Re: Selecting values from comma separated string
In-Reply-To: <162867790908260632o685077a7xc125871fd1f6149@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox