Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id AE80163274A for ; Fri, 3 Apr 2009 18:03:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 18643-01 for ; Fri, 3 Apr 2009 18:03:23 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.237]) by mail.postgresql.org (Postfix) with ESMTP id 072A063264E for ; Fri, 3 Apr 2009 18:03:27 -0300 (ADT) Received: by rv-out-0506.google.com with SMTP id l9so1249816rvb.43 for ; Fri, 03 Apr 2009 14:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=8Q/qBFUd/LB9qDOmaMhRxVxE00I5vo1tfiTctqzTIYg=; b=mvcY9Iwdav6l3SZt2CbA8PLeze+mfKs43GJunsvClKUqwJ8SDe38kpKUDi64Ql70ui swQG30E0sNtXHAM+hPRtdSD7kUg3T+P4/agqMNa7MGl7cNudCpvfMZKOttgitE0IZphq vY3PhnoaBcwAJ1YJW9ueMLgAkpFoN+cfHE7ec= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=u+9BnhbMT0ayNDuc9VT7zWtP+EZUIU311NyQx49gEjvJlgUxPBDPBoe+tPBr+FNMAM IOMfVvHExGkWjXnztJ3IxaSkDvzzQadFFwsFOPk+ZXD+Zky8+zCWADOeGd40iVyIhGkB yhz7QtSW6HKrHv8ty1qfpwpW9r0DsE/OOe3hI= MIME-Version: 1.0 Received: by 10.141.210.13 with SMTP id m13mr719080rvq.181.1238792606139; Fri, 03 Apr 2009 14:03:26 -0700 (PDT) Date: Fri, 3 Apr 2009 16:03:26 -0500 Message-ID: <4544e0330904031403i218fdb3cxf18d8971ff284290@mail.gmail.com> Subject: pl/pgsql or control structures outside of a function? From: Peter Koczan To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/37 X-Sequence-Number: 32383 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