我想做这样的事情:
...
with blocking_index as (
(select * from exact_phone_matches) union all (select * from
exact_email_matches)
),
matched_names as (
select * from get_matches((_rec.name, 'blocking_index')
)
)
...
即我想将对我的 CTE 别名('blocking_index')的引用传递到一个函数中。该函数包含如下内容:
return query execute format('select * from %s where %s', _table, _whr)
这行不通。我还有其他方法可以做到这一点吗?
最佳答案
您不能使用 CTE 执行此操作,因为 CTE 在定义它的查询之外没有任何意义。
您可以使用临时表。这具有额外的优势,您可以对其进行ANALYZE
,以便优化器具有统计信息,而这对于 CTE 是不可能的。
关于postgresql - Postgres : Refer to CTE alias within function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49253747/