Andy Gimblett <A.M.Gimblett@swansea.ac.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