I can pass variables into PostgreSQL using
psql --variable="var='value'" <<<'SELECT :var'
...and refer to them as, in this case, :var
in SQL queries passed to psql on stdin.
However, this doesn't work from code using PL/PGSQL:
psql --variable=var="'value'" <<'EOF'
DO $$
BEGIN
SELECT :var;
END;
$$
EOF
...yielding the error:
ERROR: syntax error at or near ":"
How can this be resolved?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…