-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.

1
  • 2
    psql ... -c 'update ...' Commented Oct 16, 2019 at 8:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.