我MATCH_RECOGNIZE
在带有几个 CTE 的查询中使用函数。当我运行查询时,出现以下错误:
SQL 编译错误:此上下文不支持 MATCH_RECOGNIZE。
在我的查询中,在 MATCH_RECOGNIZE 之前和之后有几个 CTE,如下所示。
WITH cte1 AS (
SELECT *
FROM dataset
WHERE ID IS NOT NULL AND STATUS IS NOT NULL ),
cte2 AS (
SELECT *
FROM cte1
QUALIFY FIRST_VALUE(STATUS) OVER (PARTITION BY ID ORDER BY CREATED_AT) = 'created' )
mr as (
SELECT *
FROM cte2
MATCH_RECOGNIZE (
PARTITION BY ID
ORDER BY CREATED_AT
MEASURES MATCH_NUMBER() AS mn,
MATCH_SEQUENCE_NUMBER AS msn
ALL ROWS PER MATCH
PATTERN (c+m+)
DEFINE
c AS status='created'
,m AS status='missing_info'
,p AS status='pending'
) m1
QUALIFY (ROW_NUMBER() OVER(PARTITION BY mn, ID ORDER BY msn) = 1)
OR(ROW_NUMBER() OVER(PARTITION BY mn, ID ORDER BY msn DESC)=1)
ORDER BY ID, CREATED_AT ),
cte3 as (
SELECT *
FROM mr
-- some other operations
)
解决这个问题的理想方法是什么?例如,创建常规视图、物化视图或临时表等。我尝试创建视图但出现错误,不确定是否支持。我如何使用MATCH_RECOGNIZE
其他后续 CTE 中的结果?
当我添加以下内容时,会出现此错误:
位置 0 处的语法错误行 xx 意外“创建”。
create view filtered_idents AS
SELECT *
FROM cte2
MATCH_RECOGNIZE (
)