Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5C2FE2E2DF0 for ; Sat, 29 Dec 2007 03:29:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 46852-02 for ; Sat, 29 Dec 2007 03:29:23 -0400 (AST) Received: from hu-out-0506.google.com (hu-out-0506.google.com [72.14.214.237]) by postgresql.org (Postfix) with ESMTP id 950E42E2DF4 for ; Sat, 29 Dec 2007 03:29:24 -0400 (AST) Received: by hu-out-0506.google.com with SMTP id 22so179386hug.23 for ; Fri, 28 Dec 2007 23:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=ReYXDbnd11wtazcfHgrnuEb6xbDDI3mfmiCtONkd9C4=; b=f64u1DEJNRLiHIVxnb3r8wwmIg4ZRiLios+nn9jpW/vVMDCiE0Rh3A1hY39LsOg87FGxaDhv0A75QD4ZH0rlxnY5PFrxVkSnEcQQJ8EJQVRP5rmMqIJWUgVnQwkY4eVsTFZRgvx8cwHtsn9Hm4Gl8ynD2uamERfyb/yUQTei55Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=thDRwHpCLNA2VtOVw38d54Wvtdw8xS2Y/SCKmpqyQExuXxe6593OUGE2NJtrtZLVfMGK+CHjXRtV7lUUU6ffbefL3JJgYsd2rnc4fIEf33Sji/cFCWxkwZFS+Lu1a3XfXHfveYUUUzCUmP7q9IbsJK1GNAI3MTv4djU8cL74Ph4= Received: by 10.78.122.16 with SMTP id u16mr12358099huc.28.1198913362992; Fri, 28 Dec 2007 23:29:22 -0800 (PST) Received: by 10.78.35.10 with HTTP; Fri, 28 Dec 2007 23:29:22 -0800 (PST) Message-ID: <162867790712282329x2ff4d99cyd8057ec6aca76d70@mail.gmail.com> Date: Sat, 29 Dec 2007 08:29:22 +0100 From: "Pavel Stehule" To: "Daniel Myers" Subject: Re: PL/pgsql: function passing argument to IN operator Cc: pgsql-sql@postgresql.org In-Reply-To: <455d64770712282240h3c93a2f0y9e357d1d23882b10@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <455d64770712282240h3c93a2f0y9e357d1d23882b10@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/149 X-Sequence-Number: 29841 Hello it has sense only for array type so you can try: create replace function foo(anyarray) returns bool as $$ begin return (select 1 = any($1)); end ; $$ language plpgsql; postgres=# select foo(array[1,2,3]); foo ----- t (1 row) postgres=# select foo(array[2,3]); foo ----- f (1 row) Regards Pavel Stehule On 29/12/2007, Daniel Myers wrote: > Hello list, > I'm trying to write a function that uses one of its arguments as > an input to an IN operator in a WHERE clause. I.e., something like: > > -- ids are actually integers > CREATE FUNCTION foo(ids SOMETYPE) RETURNS [whatever] AS $$ > BEGIN > SELECT id, [other stuff] FROM table WHERE [other conditions] AND > id IN (ids); > RETURN; > END > $$ plpgsql > > I had wanted to avoid using the EXECUTE statement and dynamically > creating the query string, because 1) I'd rather not recompile the > query each time and 2) I'm doing a SELECT INTO, which apparently > doesn't work with EXECUTE. > > Can anyone help me out? > > Thanks, > Daniel > > P.S.: Sorry if capitalizing SQL keywords is bad list etiquette... > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >