【发布时间】:2019-11-19 13:30:02
【问题描述】:
我在顶层有一个表 foo,在架构 bar 中有一个表 foo。
使用此查询时:
select *
from bar.foo
natural join foo
where foo.baz = 'test'
我得到错误:
ERROR: table reference "foo" is ambiguous
LINE 4: where foo.baz = 'test'
我可以通过使用别名来解决这个问题:
select *
from bar.foo
natural join foo as f
where f.baz = 'test'
但我想知道是否可以在不使用别名的情况下直接指定顶级架构(以使 SQL 清楚我不是在谈论 bar.foo)?例如这样的:
select *
from bar.foo
natural join foo
where .foo.baz = 'test'
或者像这样:
select *
from bar.foo
natural join foo
where root_schema.foo.baz = 'test'
【问题讨论】:
-
不要使用
natural join!明确列出join条件!
标签: sql postgresql database-schema