'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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source