【发布时间】:2021-06-09 19:11:36
【问题描述】:
我想在 plpgsql 函数中执行此操作
WITH set1 AS (
select *
from table1
where ... -- reduce table1 to the small working set once for multiple reuse
), query_only_for_select_into AS (
select id
into my_variable_declared_earlier
from set1
where foo = 'bar'
)
select my_variable_declared_earlier as my_bar
, *
from set1
where foo <> 'bar'
但 Postgres 抛出错误
ERROR: SELECT ... INTO is not allowed here
我猜这是因为 select ... into 在 CTE 中。但我在文档或网络上找不到任何关于它的内容。也许我只是搞砸了select ... into 语法?
【问题讨论】:
标签: postgresql common-table-expression select-into