From: Peter Koczan <pjkoczan@gmail.com>
To: pgsql-sql@postgresql.org
Subject: pl/pgsql or control structures outside of a function?
Date: Fri, 3 Apr 2009 16:03:26 -0500
Message-ID: <4544e0330904031403i218fdb3cxf18d8971ff284290@mail.gmail.com> (raw)
Hi all,
Is there any way to use PL/pgSQL code outside of a function?
The reason I'm asking is that I'm porting some code from
sybase/isql/SQR, and it allows some control code structures to be used
in an sql script. For instance,
begin
if ((select count(*) from users where login = 'foo') = 0)
begin
print 'Login "foo" does not exist.'
end
else
begin
print 'Adding account for "foo".'
insert into accounts values ('foo', 'bar')
end
end
PL/pgSQL looks like it would make this port rather easy, but all the
docs and examples I found never had an example of PL/pgSQL outside of
a function. For the purposes of this port I'd really prefer not to
create functions for all this. I searched through the PL/pgSQL docs
and even several Google searches but couldn't find a definitive
answer. It's fine if the answer is no, I'm just curious if I should
pursue this path or look for a different one. And if there's a way to
do this or something like it besides "create scripts in
Perl/Python/etc." that you know of, I'd appreciate any information.
Thanks,
Peter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pjkoczan@gmail.com
Subject: Re: pl/pgsql or control structures outside of a function?
In-Reply-To: <4544e0330904031403i218fdb3cxf18d8971ff284290@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox