Andy Gimblett <A(dot)M(dot)Gimblett(at)swansea(dot)ac(dot)uk> writes:
> Question: is there any way to use environment variables (or something
> similar) in my saved SQL code, and have them expanded at runtime?
Only by preprocessing the script. Have you considered something like
cat <<EOF
... WHERE $foo = ...
EOF | psql ...
regards, tom lane