From: | derrick(at)grifflink(dot)com |
---|---|
To: | "Stephan Szabo" <sszabo(at)megazone(dot)bigpanda(dot)com> |
Cc: | <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: plpgsql function Syntax |
Date: | 2004-09-02 03:20:03 |
Message-ID: | 00fc01c4909b$bd9e5f20$0200a8c0@main |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Excellent! Thank you.
Derrick
----- Original Message -----
From: "Stephan Szabo" <sszabo(at)megazone(dot)bigpanda(dot)com>
To: <derrick(at)grifflink(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Sent: Wednesday, September 01, 2004 8:32 PM
Subject: Re: [NOVICE] plpgsql function Syntax
>
> On Wed, 1 Sep 2004 derrick(at)grifflink(dot)com wrote:
>
> > Is it possible to get a select statement to work like this with a for
loop?
> >
> > CREATE FUNCTION public.search(int4)
> > RETURNS SETOF search1 AS
> > '
> > DECLARE
> > category alias for $1;
> > newrows search1%rowtype;
> > rec RECORD;
> > SQLCommand varchar;
> >
> > BEGIN
> > IF (category = 0) THEN
> > SQLCommand := 'SELECT * FROM table';
> > ELSE
> > SQLCommand := 'SELECT idnumber FROM table';
> > END IF;
> >
> > FOR rec IN SQLCommand
> > LOOP
> > ...blah...
> > ...blah...
> > END LOOP;
> >
> > Basically I want to create the SELECT statement dynamically and then use
> > that select statement in subsequent querries later in the function.
Will
> > this syntax work or should I try to use a VIEW?
>
> You should be able to use FOR rec IN EXECUTE SQLCommand LOOP to execute
> the string and loop over the results I think.
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | operationsengineer1 | 2004-09-02 06:23:47 | pgsql revision question |
Previous Message | Stephan Szabo | 2004-09-02 02:32:37 | Re: plpgsql function Syntax |