recursive text construction in plpgsql? - Mailing list pgsql-general

From Frank Miles
Subject recursive text construction in plpgsql?
Date
Msg-id Pine.A41.4.33.0109071534300.83830-100000@mead1.u.washington.edu
Whole thread Raw
Responses Re: recursive text construction in plpgsql?
List pgsql-general
The simple recursive function:

--
DROP FUNCTION testRecurse(int,int);
CREATE FUNCTION testRecurse(int,int) RETURNS text AS '
        DECLARE
                rslt                    text;
        BEGIN
                IF $1 = 0 THEN
                        rslt= CAST($2 AS TEXT);
                ELSE
                        rslt= CAST($1 AS TEXT) || '','' || testRecurse($1 - 1, $2);
                END IF;
                RETURN rslt;
        END;
' LANGUAGE 'plpgsql';
--

does not give the result I expect.  For example, for:
    SELECT testRecurse(4,3);
it seems to me that the result should be:
    4,3,2,1,3
instead of what is returned:
    1,1,1,1,3

Is this supposed to work in 7.1.3?

    -frank


pgsql-general by date:

Previous
From: Brett Schwarz
Date:
Subject: Re: Problem w/ dumping huge table and no disk space
Next
From: David Ford
Date:
Subject: Re: Problem w/ dumping huge table and no disk space