gpt4 book ai didi

PostgreSQL 错误 : column "i" of relation "inventory" does not exist

转载 作者:行者123 更新时间:2023-11-29 12:56:47 25 4
gpt4 key购买 nike

我有一个数据库,我需要根据另一个表的注册表更新某个表上的数据。由于我有点受困,能否获得有关如何操作的帮助。

我有这个选择查询作为引用:

select i.* 
from transaction as 't'
inner join transaction_detail as 'td'
on t.id_transaction=td.id_transaction
inner join inventory as 'i'
on i.id_inventory=td.id_inventory
where t.registered_date>='2016-09-01';

我想做的是根据表 t 中的日期更新表 i 中的一个字段,所以它会像这样:

update inventory i
set i.status='cancel'
from transaction_detail td
inner join transaction t
on t.id_transaction=td.id_transaction
where t.registered_date>='2016-09-01'
and i.id_inventory=td.id_inventory;

我在 postgres 上做这个,有什么建议吗?我应该尝试使用函数来执行此操作吗?

编辑:如果有帮助的话,列之间的关系是从交易到交易详情的一对多关系,以及从交易详情到库存的一对一关系。

最佳答案

参见 https://www.postgresql.org/docs/9.3/static/sql-update.html

column_name The name of a column in the table named by table_name. The column name can be qualified with a subfield name or array subscript, if needed. Do not include the table's name in the specification of a target column — for example, UPDATE tab SET tab.col = 1 is invalid.

所以你需要把set i.status='cancel'改成set status='cancel'

关于PostgreSQL 错误 : column "i" of relation "inventory" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41232605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com