Re: How to write a function that manipulates a set of results

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to write a function that manipulates a set of results
Date: 2007-03-14 19:02:42
Message-ID: 20070314190242.GA5105@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ashley Moran <work(at)ashleymoran(dot)me(dot)uk> schrieb:

>
> On Mar 14, 2007, at 6:02 pm, Andreas Kretschmer wrote:
> >select * from <insert_your_srf-function_here>.
> >For instance, if your SRF-function is called foo(), do:
> >select * from foo();
>
>
> Andreas,
>
> It's more complicated than that. What we need to do is something along
> the lines of:
>
> results = SELECT * FROM foo();

Try something like:

create results as SELECT * FROM foo();

Than you can do:

> DELETE FROM results WHERE (some condition involving results);
> some_value = SELECT value FROM results WHERE (etc);

Try: create table some_value as SELECT value FROM results WHERE (etc);

>
> and so on...

Yes, and so on...

>
> All of which is easy with table variable, but I can't see how to translate
> it to PL/pgsql. Is there any way to manipulate result sets in a set-based
> manner like this?

You can do a lot in pl/pgsql. For some things, for instance dynamically
created SQLs, you need EXECUTE. But you can do a lot with pl/pgsql.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-03-14 19:07:10 Re: quoted identifier behaviour
Previous Message Vivek Khera 2007-03-14 19:00:50 Re: grant permissions to set variable?