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 年前2234 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则