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
posta 2 anni fa2233 visualizzazioni
2 Risposte
1
Risposta accettata

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
ESPERTO
Chris_G
con risposta 2 anni fa
AWS
ESPERTO
verificato 2 anni fa
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
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande