improves/fixes variable substitution for postgres