Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have some sql in a varible. I could put that in a file and give it to psql as input but I wonder if there is an easy way to do this without the file ?

share|improve this question
Can you add some more detail please? Maybe some information about how the variable was filled, what with, what you want it to do, what language you're working in, etc. – Majenko Mar 31 '11 at 13:42

You can either pipe the command to psql

echo "$some_sql_in_a_varible" | psql -d mydatabase 

or use -c

psql -d database -c "$some_sql_in_a_varibl"

Mor info on the psql man page

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.