4
votes

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;
3

3 Answers

5
votes

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.

1
votes

Athena does not support Parameterized queries. How ever you can create user-defined functions that you can call in the body of a query. Refer to this to know more about UDFs.

1
votes

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