X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BE9E856439 for ; Tue, 15 Mar 2005 14:20:17 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52400-05 for ; Tue, 15 Mar 2005 14:20:16 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 2A72B564F0 for ; Tue, 15 Mar 2005 14:20:13 +0000 (GMT) Received: (qmail 25401 invoked from network); 15 Mar 2005 15:20:21 +0100 Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4) by boutiquenumerique.com with SMTP; 15 Mar 2005 15:20:21 +0100 To: lucap@personainternet.com, pgsql-sql@postgresql.org Subject: Re: select multiple immediate values, but in multiple rows References: <200503142318.27510.lucap@shaw.ca> Message-ID: Date: Tue, 15 Mar 2005 15:20:14 +0100 From: PFC Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: <200503142318.27510.lucap@shaw.ca> User-Agent: Opera M2/7.54 (Linux, build 955) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/222 X-Sequence-Number: 20701 You need a function like this : CREATE OR REPLACE FUNCTION array_srf( integer[] ) RETURNS SETOF integer LANGUAGE PLPGSQL etc... AS $$ DECLARE _data ALIAS FOR $1; _i INTEGER; BEGIN FOR _i IN 1..icount(_data) LOOP RETURN NEXT _data[_i]; END LOOP; RETURN; END; $$ select * from array_srf('{1,2,3,4}'); array_srf ----------- 1 2 3 4 (4 lignes) This will avoid you the UNION. > Hello all. I'd like to write a query does a set subtraction A - B, but > A is > is a set of constants that I need to provide in the query as immediate > values. I thought of something like > > select a from (1,2,3.4) > except > select col_name from table; > > but I don't know the syntax to specify my set of constants. I thought of > doing > select 1 union select 2 union select 3 union ... except ... > but I figure there must be a better way. The size of the set would be > anywhere between 1 and about 5 or 6 elements. Is there a better way to > do > this? > > Thanks. > > Luca > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend >