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

786 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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