I did some research and haven't yet found if this is possible, but does anyone know if you can specify a parameter for an AWS Athena Query?
For example, I want my query to be able to filter WHERE merchant_id = {merchant_id}
. Is it possible to specify this so that I could use the same query for every merchant I want? And if so, where would I pass in the input to the Athena query?
One cannot set variables with AWS Athena. Since Athena can run only one query in a session.
If you try to run more than one query you will get the following error.
Hope it helps.
I appreciate this thread is a little old, but it's one of the first results I found when trying to do the same. I'm not sure if there would be significant performance issues, and I'm certain it can be improved upon, but the theory is as follows:
Using Athena's accepted WITH function, create a couple of queries to hold your variables, join these to your original query/table and then use them within the filters.
WITH startdate AS (SELECT DATE('2019-12-01') AS v_startdate), enddate AS (SELECT DATE('2019-12-31') AS v_enddate)
SELECT *SQL HERE* FROM table_name
LEFT JOIN startdate ON 1=1
LEFT JOIN enddate ON 1=1
WHERE table_name.start_date >= v_startdate
AND table_name.end_date <= v_enddate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With