passing vsql string and date variables from bash shell to sql file
How can I pass variables that require wrapping in single quotes (i.e. strings and dates) to a sql file using vsql from a bash command? vsql parameter substitution works fine for types that don't require single quote wrapping (int, numeric) in the sql, but I haven't found any examples that demonstrate usage with a type requiring quotes.
var_test.sql:
select table_name from tables where table_name = :table_name;
command:
$ vsql -d my_db -h localhost -w my_pwd -f ./var_test.sql -v table_name=my_table_name -e
The example above passes the :table_name variable in from the command line, but the sql throws an error because the table name is not wrapped in single quotes ("column "my_table_name" does not exist"). If I wrap the :table_name variable in single quotes, the parameter substitution breaks.
Thanks,
Dave Uchimoto
var_test.sql:
select table_name from tables where table_name = :table_name;
command:
$ vsql -d my_db -h localhost -w my_pwd -f ./var_test.sql -v table_name=my_table_name -e
The example above passes the :table_name variable in from the command line, but the sql throws an error because the table name is not wrapped in single quotes ("column "my_table_name" does not exist"). If I wrap the :table_name variable in single quotes, the parameter substitution breaks.
Thanks,
Dave Uchimoto
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
