I cannot use current_date + interval in Athena boto3 query in Lambda

0

I am attempting to use Lambda to run an Athena query in order to schedule it to run weekly for a report. When i run the query directly in Athena, I get results. When i run it as a python boto3 query, it does not work if I attempt to use 'current_date + interval

Working in Athena Query Editor: SELECT * FROM "datebasename"."table" where date < current_date + interval '1' day);

**Error when ran from Lambda **

Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 6)
"stackTrace": [
    "  File \"/var/task/lambda_function.py\" Line 6\n    query ='SELECT * FROM \""datebasename"\".\"table\" where date < (current_date + interval '1' day))'\n"
  ]

If I remove the '+ interval '1' day' from the lambda athena query , it works. I have tried with parenthesis, as well as tried using date_add, with similar results when i use an interval.

Is there something I need to change to allow interval to work in boto3 athena query?

mkwtx
已提問 2 年前檢視次數 2233 次
2 個答案
1
已接受的答案

It looks like a syntax error. You have the query wrapped in single quotes in your python code and also have the '1' wrapped in single quotes. You will need to either escape the single quotes on the '1' or remove the single quotes.

profile pictureAWS
專家
Chris_G
已回答 2 年前
AWS
專家
已審閱 2 年前
0

That was it! I think the output was a little misleading, but you were right. I had to escape the single quotes of the '1' in the boto3 athena query, which was not necessary in athena query editor.
FYI, removing the quotes did work, and resulted in another syntax error. Thanks you!

mkwtx
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南