为什么postgres不能理解对派生列的引用?

时间:2013-06-12 09:21:00

标签: sql postgresql

所以我有这个问题:

select 
   id, 
   unnest(suppliers) as suppliercode
from table1 t1
left join table2 t2
on t1.suppliercode = t2.suppliercode

Postgres无法理解其含义:

on t1.suppliercode = t2.suppliercode

t2.suppliercode 引起混淆。为什么?如何显式调用新的派生列?

1 个答案:

答案 0 :(得分:1)

t1.suppliercode表示“表suppliercode中的列t1”。而你的表t1没有这样的列。尝试类似:

select *
from(select t1.id, 
            unnest(t1.suppliers) as suppliercode
     from table1 t1 ) sub
left join table2 t2
on sub.suppliercode = t2.suppliercode