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
feita há 2 anos2233 visualizações
2 Respostas
1
Resposta aceita

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
ESPECIALISTA
Chris_G
respondido há 2 anos
AWS
ESPECIALISTA
avaliado há 2 anos
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
respondido há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas