【发布时间】:2015-08-30 05:41:37
【问题描述】:
这是我正在尝试编写的 PSQL 命令:
UPDATE accounts
SET account_type_id=subquery.id
FROM (SELECT id
FROM account_types
WHERE mongo_id = accounts.mongo_account_type_id) AS subquery
WHERE accounts.id = 1;
产生此错误消息:
错误:对表“accounts”的 FROM 子句条目的引用无效 第 1 行:...OM (SELECT id FROM account_types WHERE mongo_id = 帐户.m... ^ 提示:表“accounts”有一个条目,但无法引用 来自查询的这一部分。
数据结构的简短说明 - 从 MongoDB 迁移到 PSQL,我已将所有记录移至 PSQL,维护旧的 Mongo BSON 以引用和重新缝合具有外键关系的记录 - 我的帐户表具有如下列:
mongo_id | 521289ae1e0345000200000f
mongo_merchant_id | 55e13f0afbab68982e000006
mongo_account_type_id | 521289c41e03450002000011
mongo_admin_id | 518b762e89651a0389000013
我的 account_types 表有:
mongo_id | 521289c41e03450002000011
mongo_merchant_id | 55e13f0afbab68982e000006
所以我尝试使用 accounts.mongo_account_type_id == account_types.mongo_id 作为参考,将我的 ACCOUNTS 表的 account_type_id 字段设置为 ACCOUNT_TYPES 表中 id 字段的 INTEGER 值。
最终,账户应该有 account_type_id = 1(在这种情况下 - 在这种特殊情况下,account_type 的记录是 id 1)
在我的查询中,我只是对如何使用 accounts 表作为 mongo_account_type_id 的“变量”进行子查询感到困惑。
【问题讨论】:
标签: sql postgresql