By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Is it possible to execute query in shell script??

P: 2
Having a database created, is it possible to excute queries on this database from a shell script file??
Oct 6 '10 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 700
You mean something like that
Expand|Select|Wrap|Line Numbers
  1. psql database_name < file.sql
  2.  
or that
Expand|Select|Wrap|Line Numbers
  1. psql database_name -f file.sql
  2.  
Oct 6 '10 #2

P: 2
Can you explain ur answer further..i dont get what you mean..
Oct 7 '10 #3

Expert 100+
P: 700
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
Expand|Select|Wrap|Line Numbers
  1. psql databasename -c "<query>"
  2.  
Do you understand now?
Oct 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.