Re: running scripts like oracle sqlplus

From: Brian Sherwood <bdsher(at)gmail(dot)com>
To: Steven Dahlin <pgdb(dot)sldahlin(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: running scripts like oracle sqlplus
Date: 2010-06-21 21:01:27
Message-ID: AANLkTinIKyQPRROJKIPvwmRIppRyxvlEWnUJH1tikve4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Have you tried nextval & currval?
http://www.postgresql.org/docs/8.4/interactive/functions-sequence.html

Something like this:

begin

insert into user
(
user_id,
customer_id,
create_user,
update_user
)
values
(
nextval(user_seq),
nextval(customer_seq),
currval(user_seq),
currval(user_seq)
);

insert into customer
(
customer_id,
create_user,
update_user
)
values
(
currval(customer_seq),
currval(user_seq),
currval(user_seq)
);

commit;

end;

On Fri, Jun 18, 2010 at 6:24 PM, Steven Dahlin <pgdb(dot)sldahlin(at)gmail(dot)com>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
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tim Landscheidt 2010-06-21 21:44:56 Re: error on line 1 trying to execute a script using psql
Previous Message Kenneth Marshall 2010-06-21 18:52:06 Re: running scripts like oracle sqlplus