DB Table Selector with Flow Variables

I have a small workflow trying to build. Pulling data from an Amazon Redshift Connector. I want the option for variable dates based on inputs.

I created a component that gives a start and end date (named varStartDate and varEndDate). Passed through to Table Row to Variable.

The Amazon Redshift Connector was successful, and passes through to the DB Table Selector and passes through successfully, as does the DB Reader.

(the FROM is not actual, changed for privacy issues). I have a simple query where I want to bring back all data starting on varStartDate and if possible, end varEndDate.

I’ve put varStart Date in sql_statement (and custom_query), but my output contains ALL dates

For this example, here is the start/end date:

All dates are being returned:

I’m sure this is operator error, what am I missing?

Hi @ebarr , try putting the flow variable inside single quotes,

WHERE "date" >= '$${SvarStartDate}$$'

The DB nodes perform direct string replacement of flow variables so you still need to put in any single quotes to make the statement syntactically (and semantically) correct. At the moment, when the string replacement of the flow variable occurs, your sql statement will become this:

WHERE "date" >= 2024-01-01

On many databases this would generate an error, because it is actually comparing a date with an integer (2022) … the result of 2024 minus 1 minus 1 :slight_smile:

I can only presume that Amazon Redshift is happy to compare dates with integers.

By adding the single quotes, it will become this:

WHERE "date" >= '2024-01-01'

which should then give the result you are expecting.


That was simple enough, thank you!!

1 Like

You’re welcome @ebarr. Glad it worked.

Thanks for marking the “solution” so people with a similar question are directed to the answer :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.