Re: select multiple immediate values, but in multiple rows - Mailing list pgsql-sql

From PFC
Subject Re: select multiple immediate values, but in multiple rows
Date
Msg-id opsnonf00zth1vuj@localhost
Whole thread Raw
In response to select multiple immediate values, but in multiple rows  (Luca Pireddu <lucap@shaw.ca>)
List pgsql-sql
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
>




pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: outputting dates
Next
From: Tom Lane
Date:
Subject: Re: Parameterized views proposition