PostgreSQL: How to pass parameters from command line?

前端 未结 7 664
孤独总比滥情好
孤独总比滥情好 2020-12-23 15:42

I have a somewhat detailed query in a script that uses ? placeholders. I wanted to test this same query directly from the psql command line (outside the script

相关标签:
7条回答
  • 2020-12-23 16:34

    In psql there is a mechanism via the

    \set name val
    

    command, which is supposed to be tied to the -v name=val command-line option. Quoting is painful, In most cases it is easier to put the whole query meat inside a shell here-document.

    Edit

    oops, I should have said -v instead of -P (which is for formatting options) previous reply got it right.

    0 讨论(0)
提交回复
热议问题