奇怪的postgresql行为

时间:2010-03-19 14:17:59

标签: postgresql

有人可以解释一下为什么会这样吗?

=> select client_id from clients_to_delete;
ERROR:  column "client_id" does not exist at character 8

但是,当把它放在IN()...

中时
=> select * from orders where client_id in(select client_id from clients_to_delete);

它有效!并选择orders表中的所有行。运行删除/更新时相同。 为什么它不像以前那样产生错误?

谢谢!

1 个答案:

答案 0 :(得分:4)

在此查询中

SELECT  *
FROM    orders
WHERE   client_id IN
        (
        SELECT  client_id
        FROM    clients_to_delete
        )

client_id取自外部表(orders),因为内部表(clients_to_delete)中没有具有此类名称的字段:

SELECT  *
FROM    orders
WHERE   orders.client_id IN 
        (
        SELECT  orders.client_id
        FROM    clients_to_delete
        )
相关问题