Postgres:请参阅函数中的CTE别名

时间:2018-03-13 10:27:08

标签: postgresql common-table-expression

我想做这样的事情:

...
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)

这不起作用。还有其他办法吗?

1 个答案:

答案 0 :(得分:0)

对于在定义它的查询之外没有任何意义的CTE,你不能这样做。

您可以使用的是临时表。这有一个额外的好处,你可以ANALYZE它,以便优化器具有统计数据,这是CTE无法实现的。

相关问题