Re: simple plpgsql / sql function question - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: simple plpgsql / sql function question
Date
Msg-id b42b73150803111053m130a91d5w49ff772b5ca36deb@mail.gmail.com
Whole thread Raw
In response to simple plpgsql / sql function question  (Joshua <joshua@joshuaneil.com>)
Responses Re: simple plpgsql / sql function question  ("Merlin Moncure" <mmoncure@gmail.com>)
Re: simple plpgsql / sql function question  (Joshua <joshua@joshuaneil.com>)
List pgsql-hackers
On Tue, Mar 11, 2008 at 1:26 PM, Joshua <joshua@joshuaneil.com> wrote:
> Hello,
>
>  I have a series of SQL Update statements. I would like to write a
>  function which runs all of the SQL Update statements one at a time, in
>  order from top to bottom. Can somebody share the basic syntax that I
>  would need to write the aforementioned function?

please ask future questions of this nature on the general list.  the
hackers list is reserved for things pertaining to postgresql
development.

anywyays, the answer is easy:
sql (imo preferred for this case):
create function do_stuff returns void as
$$ update foo set bar = 1 where foo_id = 2; [repeat as necessary]
$$ language sql;

plpgsql:
create function do_stuff returns void as
$$ begin   update foo set bar = 1 where foo_id = 2;   [repeat as necessary] end;
$$ language plpgsql;

merlin


pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Patch for Prevent pg_dump/pg_restore from being affected by statement_timeout
Next
From: "Merlin Moncure"
Date:
Subject: Re: simple plpgsql / sql function question