command-lineverticavsql

How to pass multiple name value pairs to an SQL file using vsql -v from a bash script?


How to pass multiple parameters to a SQL file using vsql command line option?

The following is working with asingle argument:

/vsql -h${SERVER} -U${USER} -w${PWD} -A -t -P fieldsep=, -f test.sql -v date1="'"${FIRSTDAY}"'" > test.csv

But I also want to pass last date:

/vsql -h${SERVER} -U${USER} -w${PWD} -A -t -P fieldsep=, -f test.sql -v date1="'"${FIRSTDAY}"'" date2="'"${LASTDAY}"'" > test.csv

but this throws an error:

Database "date2='20160131'" does not exist


Solution

  • Simply repeat the -v option as many times as needed:

    vsql -h${SERVER} -U${USER} -w${PWD} -A -t -P fieldsep=, -f test.sql \
    -v date1="'"${FIRSTDAY}"'" -v date2="'"${LASTDAY}"'" > test.csv