Athena Query - Correlated subquery not supported

0

This query works outside of Athena (in DB2). For the most part it's working in Athena when I comment out the "having max(column1) > 3" line. But, the error that Athena returns when I RUN, is saying SYNTAX_ERROR: line 23:9: Given correlated subquery is not supported. The line corresponds with "and not exists":

select
*
from t1
where
product = 'SHIRT'
and t1.year = '2022' and t1.month = '07' and t1.day ='31'
and not exists
(
select max(column1) from a2
        where trim(a2.id) = trim(t1.id) --these are strings with trailing spaces, hence the trim here
        having max(column1) > 3
        )
limit 10

It's not like Athena hates the having clause because I wrote a statement as such and it worked: select max(column1) from a2 having max(column1) > 3

It's not the "and not exists" statement because I have used that previously and it worked.

I cannot figure out what Athena is fussing about.

已提問 2 年前檢視次數 2252 次
2 個答案
0

I've run into the same thing in Hive, but I'm not familiar with Athena. Try coding the A2 table as a join statement, not in the where clause and then in the where clause do the filtering. Let me know if that works. Here's an example of how that's done.
https://stackoverflow.com/questions/37215092/working-around-unsupported-correlated-where-subqueries-in-hive

已回答 2 年前
0

NOT EXISTS is indeed supported in presto and thus in Athena too. The error is also not very descriptive to conclude the reason. I found one issue with your query that you are using HAVING clause without GROUP BY. Try to make amendment's in your query based on your requirements.

AWS
支援工程師
Shubh
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南