Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Athena - How to Parameterize the SQL query

I want to provide runtime values to the query in Select & Create table statements. What are the ways to parameterize Athena SQL queries? I tried with PREPARE & EXECUTE statements from Presto however it is not working in Athena console. Do we need any external scripts like Python to call it?

PREPARE my_select1
FROM SELECT * from NATION;

EXECUTE my_select1 USING 1;
like image 586
Rajeev Avatar asked Mar 09 '23 08:03

Rajeev


2 Answers

The SQL and HiveQL Reference documentation does not list PREPARE nor EXECUTE as available commands.

You would need to fully construct your SELECT statement before sending it to Amazon Athena.

like image 180
John Rotenstein Avatar answered Mar 20 '23 21:03

John Rotenstein


You have to upgrade to Athena engine version 2 and now this seems to be supported as of 2021-03-12 but I can't find an official report:

https://docs.aws.amazon.com/athena/latest/ug/querying-with-prepared-statements.html

like image 41
gordy Avatar answered Mar 20 '23 22:03

gordy