Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 397D163361C for ; Wed, 26 Aug 2009 11:05:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 19789-07 for ; Wed, 26 Aug 2009 14:05:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E96B4633549 for ; Wed, 26 Aug 2009 11:05:09 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n7QE58SW011646; Wed, 26 Aug 2009 10:05:08 -0400 (EDT) To: "A. Kretschmer" cc: pgsql-sql@postgresql.org Subject: Re: Selecting values from comma separated string In-reply-to: <20090826133036.GK32599@a-kretschmer.de> References: <20090826133036.GK32599@a-kretschmer.de> Comments: In-reply-to "A. Kretschmer" message dated "Wed, 26 Aug 2009 15:30:36 +0200" Date: Wed, 26 Aug 2009 10:05:08 -0400 Message-ID: <11645.1251295508@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.596 tagged_above=-10 required=5 tests=AWL=0.003, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/131 X-Sequence-Number: 33040 "A. Kretschmer" 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