From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: Selecting values from comma separated string
Date: Wed, 26 Aug 2009 15:30:36 +0200
Message-ID: <20090826133036.GK32599@a-kretschmer.de> (raw)
In-Reply-To: <f16f7ea00908260619t59555d37u66bebfe47132304f@mail.gmail.com>
References: <f16f7ea00908260619t59555d37u66bebfe47132304f@mail.gmail.com>
In response to Nacef LABIDI :
> 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);
Use EXECUTE sql_string, see
http://www.postgresql.org/docs/8.4/interactive/plpgsql-control-structures.html
For instance, simple example, untested:
create function foo (my_string) returns setof record as $$
declare
sql text;
begin
sql:='SELECT * FROM my_table WHERE id IN (' || $1 || ')';
return query execute sql;
end;
The variable sql contains the whole query, and then execute that.
HTH, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
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: andreas.kretschmer@schollglas.com
Subject: Re: Selecting values from comma separated string
In-Reply-To: <20090826133036.GK32599@a-kretschmer.de>
* 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