0

From the psql command documentation, the --variable command described as making variables available for substitution with :name syntax. However,

psql --variable=var="'hello'" -c 'select :var'

...results in a syntax error:

ERROR:  syntax error at or near ":"
LINE 1: select :var
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441

1 Answers1

1

This works correctly if the query text is fed in on stdin in bash:

psql --variable=var="'hello'" <<<"select :var"

Or by using POSIX sh:

psql --variable=var="'hello'" <<<'EOF'
select :var
EOF
ivvi
  • 5,120
  • 5
  • 36
  • 53
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441