PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 30th, 2012, 05:12 AM
giventime giventime is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 2 giventime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 7 sec
Reputation Power: 0
The lack of sqlplus is making me write more scripts

Lacking sqlplus, in postgres what I'm doing for my
input script is, I'm generating an sql query, I'm
storing the query in an external sql file, I'm running

psql mydatabase -f eachseparatesql_query.sql


Whereas for my oracle databases I do almost the same
thing, except after each query I don't need to spit it
into a separate external sql file. I can save it in a
HERE document and run it via sqlplus.

So, in short, my question is: How can I run a series of
psql queries without creating a separate external file
each time?

Reply With Quote
  #2  
Old April 30th, 2012, 05:20 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 41 m 51 sec
Reputation Power: 284
I don't understand your problem. Just put all your statements into a single file and run it?

How exactly do you call those files in SQL*Plus?
What exactly is the contents of those files?

Are you aware of psql's \i command (which corresponds to @ in sqlplus?

Reply With Quote
  #3  
Old April 30th, 2012, 05:39 AM
giventime giventime is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 2 giventime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 7 sec
Reputation Power: 0
I can't put all the queries in one file because the script actually generates each query separately, ie the queries don't exist until the script starts running. (Thanks, I'll investigate the /i option)

Reply With Quote
  #4  
Old April 30th, 2012, 09:20 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 41 m 51 sec
Reputation Power: 284
So you are actually looking for the SPOOL equivalent.

Code:
postgres=# \t
Showing only tuples.
postgres=# \o drop.sql
postgres=# select 'drop sequence '||sequence_name||';' from information_schema.sequences;
postgres=# \o
The file drop.sql now contains the following content:
Code:
 drop sequence foo;
Which can be run using \i
Code:
postgres=# \i drop.sql
DROP SEQUENCE
postgres=# commit;
COMMIT
postgres=#


Do have a look at the manual it's all in there:
http://www.postgresql.org/docs/current/static/app-psql.html

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > The lack of sqlplus is making me write more scripts

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap