Is it possible to execute query in shell script??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lakk
    New Member
    • Oct 2010
    • 2

    Is it possible to execute query in shell script??

    Having a database created, is it possible to excute queries on this database from a shell script file??
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    You mean something like that
    Code:
    psql database_name < file.sql
    or that
    Code:
    psql database_name -f file.sql

    Comment

    • lakk
      New Member
      • Oct 2010
      • 2

      #3
      Can you explain ur answer further..i dont get what you mean..

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        If you have a shell script and you want to call queries from this script you can do it using psql client. Queries you can put into file and use -f paremeter or you can use -c parameter and put queries explicitly
        Code:
        psql databasename -c "<query>"
        Do you understand now?

        Comment

        Working...