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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠