#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    2
    Rep 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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,781
    Rep Power
    348
    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?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    2
    Rep 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)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,781
    Rep Power
    348
    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

IMN logo majestic logo threadwatch logo seochat tools logo