-2

I have a need to run a query for maintenance reasons as below using psql

psql -U postgres -d test 'update sometbl set col1 = true;'

I could put the query in a sql file and run it using -f option but I really need this to run from within a bash script and don't want to have to use an additional sql file for this simple query.

mekbib.awoke
  • 1,094
  • 1
  • 9
  • 16

1 Answers1

5

You can execute a command via the psql command line interface with the parameter -c.

So in your example, this would be:

psql -U postgres -d test -c 'update sometbl set col1 = true;'

Refer to the documenation of psql here: https://www.postgresql.org/docs/9.2/app-psql.html

lobetdenherrn
  • 303
  • 1
  • 8