Re: simple plpgsql / sql function question

Lists: pgsql-hackers
From: Joshua <joshua(at)joshuaneil(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: simple plpgsql / sql function question
Date: 2008-03-11 17:26:22
Message-ID: 47D6C0BE.9040004@joshuaneil.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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 let me know.

Thanks


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: joshua(at)joshuaneil(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: simple plpgsql / sql function question
Date: 2008-03-11 17:53:39
Message-ID: b42b73150803111053m130a91d5w49ff772b5ca36deb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Mar 11, 2008 at 1:26 PM, Joshua <joshua(at)joshuaneil(dot)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


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: joshua(at)joshuaneil(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: simple plpgsql / sql function question
Date: 2008-03-11 17:54:38
Message-ID: b42b73150803111054t31ab9a23i6bf46976ffeef88e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Mar 11, 2008 at 1:53 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> > 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 [sic], the answer is easy:
> sql (imo preferred for this case):

left off parens
> create function do_stuff returns void as
create function do_stuff() returns void as

merlin


From: Joshua <joshua(at)joshuaneil(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: simple plpgsql / sql function question
Date: 2008-03-11 18:02:17
Message-ID: 47D6C929.3010503@joshuaneil.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thanks for the info. I will make sure to direct these types of questions
to the 'general' list in the future.

Thanks again for your help!!!

Merlin Moncure wrote:
> On Tue, Mar 11, 2008 at 1:26 PM, Joshua <joshua(at)joshuaneil(dot)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
>
>
>