Reputation: 295443
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
Upvotes: 0
Views: 274
Reputation: 295443
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
Upvotes: 1