Using psql, it seems possible to set named arguments using \pset somevar 'hello'. However there appears to be no way to set a positional argument like $1. This makes it difficult to paste in SQL snippets that use positional arguments. In the sqlite3 CLI, it's possible to do .param set ?1 'hello' for this purpose. How do I do this with psql?
Set placeholder argument in psql
1.3k Views Asked by Matt Joiner At
2
You need
\set(not\pset!) to set psql variables.Then you can use SQL interpolation to insert those variables into SQL commands, optionally quoting your values. Demo:
Not sure how "positional arguments" come into this ...