I'm trying to connect to a Redshift cluster and run a SQL script with parameters, but am getting errors.
Here's the Bash command:
psql -v schema="$REDSHIFT_SCHEMA" -h "$REDSHIFT_HOSTNAME" -d "$REDSHIFT_DATABASE" -U "$REDSHIFT_USERNAME" -p "$REDSHIFT_PORT" -f "nulltest.sql" -v inputStartDateId=20170318 -v inputEndDateId=20170404
And the contents of nulltest.sql
is:
select
COALESCE( $inputStartDateId, min(StartDateID)),
COALESCE( $inputEndDateId, max(EndDateID))
from (
select
row_number()over(order by FiscalWeekID desc) as rownum,
FiscalWeekID,
min(dateid)StartDateID
,max(dateid)EndDateID
from
dm.dim_Time
where DateKey < getdate()
group by FiscalWeekID
) a
where rownum <= 3
The error I'm getting is:
psql:nulltest.sql:15: ERROR: syntax error at or near "$"
LINE 2: COALESCE( $inputStartDateId, max(StartDateID))
Am I calling the parameter incorrectly in the SQL script? The SQL runs perfectly fine through Aginity when I pass values into the parameter at run time. I'm not sure what's supposed to be different when calling the SQL through the psql
command though
You're passing your parameters correctly on the command line, but your nulltest.sql file should use :inputStartDateId
or :'inputStartDateId'
instead of $inputStartDateId
. Previous answer: https://stackoverflow.com/a/30850125/6650678 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.