Rajeev
Rajeev

Reputation: 1061

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;

Upvotes: 4

Views: 10958

Answers (3)

gordy
gordy

Reputation: 9786

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

Upvotes: 3

Prabhakar Reddy
Prabhakar Reddy

Reputation: 5124

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.

Upvotes: 1

John Rotenstein
John Rotenstein

Reputation: 269370

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.

Upvotes: 5

Related Questions