pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
running scripts like oracle sqlplus
3+ messages / 3 participants
[nested] [flat]

* running scripts like oracle sqlplus
@ 2010-06-18 22:24  Steven Dahlin <pgdb.sldahlin@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Steven Dahlin @ 2010-06-18 22:24 UTC (permalink / raw)
  To: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: running scripts like oracle sqlplus
@ 2010-06-21 18:52  Kenneth Marshall <ktm@rice.edu>
  parent: Steven Dahlin <pgdb.sldahlin@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Kenneth Marshall @ 2010-06-21 18:52 UTC (permalink / raw)
  To: Steven Dahlin <pgdb.sldahlin@gmail.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: running scripts like oracle sqlplus
@ 2010-06-21 21:01  Brian Sherwood <bdsher@gmail.com>
  parent: Steven Dahlin <pgdb.sldahlin@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Brian Sherwood @ 2010-06-21 21:01 UTC (permalink / raw)
  To: Steven Dahlin <pgdb.sldahlin@gmail.com>; +Cc: 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.sldahlin@gmail.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
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-06-21 21:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-06-18 22:24 running scripts like oracle sqlplus Steven Dahlin <pgdb.sldahlin@gmail.com>
2010-06-21 18:52 ` Kenneth Marshall <ktm@rice.edu>
2010-06-21 21:01 ` Brian Sherwood <bdsher@gmail.com>

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