Search code examples
postgresqlpsqlkubectl

Add `\x on` to PostgresDB query with kubectl exec


I have a PostgresDB query which I want to run directly using kubectl exec:

kubectl exec -it -n <ns> <pod_name> -- psql -U <user> -d <db> -c "select * from <table> where id=1234;"

I want to toggle expanded output (\x on option) only for this command. I do not want to permanently enable this for all queries.

I have tried various things, such as chaining commands together with a semi-colon (i.e. \x on; select * from <table>;). I'm not getting this to work.

How do I get this to work?


Solution

  • There are several ways to do that, but the simplest is to use the -x option of psql.