X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 09FE8D1B496 for ; Fri, 28 Nov 2003 05:49:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 82286-05 for ; Fri, 28 Nov 2003 01:49:08 -0400 (AST) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id BA154D1B486 for ; Fri, 28 Nov 2003 01:49:06 -0400 (AST) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 675612; Thu, 27 Nov 2003 21:46:55 -0800 Message-ID: <3FC6E15E.2030300@joeconway.com> Date: Thu, 27 Nov 2003 21:47:10 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Huxton Cc: Andreas Tille , PostgreSQL SQL Subject: Re: Scaler forms as function arguments References: <200311261725.21975.dev@archonet.com> In-Reply-To: <200311261725.21975.dev@archonet.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/309 X-Sequence-Number: 16124 Richard Huxton wrote: > On Wednesday 26 November 2003 15:40, Andreas Tille wrote: >>I want to write a function of the following type >> >> CREATE FUNCTION test ( ) >> RETURNS setof MyTable >> AS >> 'SELECT * FROM MyTable WHERE id IN $1' >> LANGUAGE 'SQL' ; > > Not as you've done it. You could pass in text "(1,2,3)", build your query and > use EXECUTE to execute it. Alternatively, you might be able to do it with an > array parameter (sorry, I don't use arrays, so I can't be sure). In 7.4 you could use an array. It would look like this: CREATE TABLE mytable (id int, idval text); INSERT INTO mytable VALUES (1,'a'); INSERT INTO mytable VALUES (2,'b'); INSERT INTO mytable VALUES (3,'c'); CREATE FUNCTION test (int[]) RETURNS setof MyTable AS ' SELECT * FROM mytable WHERE id = ANY ($1) ' LANGUAGE 'SQL' ; regression=# SELECT * FROM test(ARRAY[1,3]); id | idval ----+------- 1 | a 3 | c (2 rows) HTH, Joe