April 30th, 2012, 05:12 AM
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
April 30th, 2012, 05:20 AM
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?
April 30th, 2012, 05:39 AM
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)
April 30th, 2012, 09:20 AM
So you are actually looking for the SPOOL equivalent.
The file drop.sql now contains the following content:Which can be run using \i
Showing only tuples.
postgres=# \o drop.sql
postgres=# select 'drop sequence '||sequence_name||';' from information_schema.sequences;
Do have a look at the manual it's all in there:
postgres=# \i drop.sql