Postgresql 如何从CTE字段别名中定义的字段集获取字段?

Postgresql 如何从CTE字段别名中定义的字段集获取字段?,postgresql,Postgresql,如何在结果查询中获取t.id和t.code?您需要在结果集中添加一个额外的括号 我已重命名您的CTE,以区分括号是指在CTE中选择的表,而不是CTE本身 with t as ( select (select t1 from table1 t1 limit 1) t, 'foo' x ) select t.id, t.code, x from t 什么是t.code?-我看不到CTE中定义了这一点。发布一些示例数据和预期结果,以说明您的预期。表1中的.t.code-列 with

如何在结果查询中获取t.id和t.code?

您需要在结果集中添加一个额外的括号

我已重命名您的CTE,以区分括号是指在CTE中选择的表,而不是CTE本身

with t as (
 select
 (select t1 from table1 t1 limit 1) t,
 'foo' x
)

select 
 t.id, t.code, x 
from t 

什么是
t.code
?-我看不到CTE中定义了这一点。发布一些示例数据和预期结果,以说明您的预期。表1中的.t.code-列
with cte as (
 select
 (select t1 from table1 t1 limit 1) t,
 'foo' x
)

select 
 (t).id, (t).code, x 
from cte