Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B7FB5632898 for ; Mon, 21 Jun 2010 15:52:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 32435-04 for ; Mon, 21 Jun 2010 18:52:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh4.mail.rice.edu (mh4.mail.rice.edu [128.42.199.11]) by mail.postgresql.org (Postfix) with ESMTP id B5CC56326FD for ; Mon, 21 Jun 2010 15:52:09 -0300 (ADT) Received: from mh4.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh4.mail.rice.edu (Postfix) with ESMTP id 34DCF37002B; Mon, 21 Jun 2010 13:52:07 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.0 at mh4.mail.rice.edu Received: from mh4.mail.rice.edu ([127.0.0.1]) by mh4.mail.rice.edu (mh4.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GBl0TkYVUnyF; Mon, 21 Jun 2010 13:52:07 -0500 (CDT) Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh4.mail.rice.edu (Postfix) with ESMTP id 8681037002E; Mon, 21 Jun 2010 13:52:07 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 289992D5A6; Mon, 21 Jun 2010 13:52:06 -0500 (CDT) Date: Mon, 21 Jun 2010 13:52:06 -0500 From: Kenneth Marshall To: Steven Dahlin Cc: pgsql-sql@postgresql.org Subject: Re: running scripts like oracle sqlplus Message-ID: <20100621185206.GB23529@aart.is.rice.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/64 X-Sequence-Number: 34255 On Fri, Jun 18, 2010 at 04:24:18PM -0600, Steven Dahlin wrote: > I have been trying to figure out how I can run a pgsql script like I can run > a plsql script with oracle's sqlplus. Here is a sample script file for what > I want to run: > > declare > sysuserid integer := 0; > hwcustid integer := 0; > begin > > select nextval( 'user_seq' ) into sysuserid; > select nextval( 'customer_seq' ) into hwcustid; > > insert into user > ( > user_id, > customer_id, > create_user, > update_user > ) > values > ( > sysuserid, > hwcustid, > sysuserid, > sysuserid > ); > > insert into customer > ( > customer_id, > create_user, > update_user > ) > values > ( > hwcustid, > sysuserid, > sysuserid > ); > > commit; > > end; > > I try to run the script in psql and thru pgadmin and cannot seem to make > them work. I do not want to turn it into a function. I just want it to > execute the block in a fashion similar to Oracle'sqlplus running > @scriptfile.sql. > > Thanks I think you will need to wait for version 9.0 and anonymous functions using DO. Cheers, Ken