Re: CASE statement and SETOF values - Mailing list pgsql-general

From Christian Schoenebeck
Subject Re: CASE statement and SETOF values
Date
Msg-id 200607251942.08858.cschoene@stud.hs-heilbronn.de
Whole thread Raw
In response to CASE statement and SETOF values  (Christian Schoenebeck <cschoene@stud.hs-heilbronn.de>)
List pgsql-general
Am Dienstag, 25. Juli 2006 17:56 schrieben Sie:
> You could use a procedural language like plpgsql.

Ok, using the plpgsql approach I tried this:

CREATE FUNCTION my_function(int4) RETURNS SETOF int8 AS
$BODY$
DECLARE
    myrow RECORD;
BEGIN
    IF (some_condition) THEN
            FOR myrow IN SELECT ... -- some select statement
            LOOP
                RETURN NEXT myrow."foocolumn";
            END LOOP;
        ELSE
            FOR myrow IN SELECT ... -- some select statement
            LOOP
                RETURN NEXT myrow."foocolumn";
            END LOOP;
    END IF;
    RETURN;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

But creating this function fails, because it's "missing a LOOP" statement.
What am I missing?

CU
Christian

pgsql-general by date:

Previous
From: Curtis Scheer
Date:
Subject: Re: Splitting Timestamps
Next
From: "Redefined Horizons"
Date:
Subject: Using currval() in an insert statement...