Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用FROM子句更新Postgres中的记录_Sql_Postgresql - Fatal编程技术网

Sql 使用FROM子句更新Postgres中的记录

Sql 使用FROM子句更新Postgres中的记录,sql,postgresql,Sql,Postgresql,我正在更改我的db模式,并将列“seat”从旧的\u表移动到新的\u表。首先,我在新表中添加了一个“seat”列。现在我尝试用旧表中的值填充该列 UPDATE new_table SET seat = seat FROM old_table WHERE old_table.id = new_table.ot_id; 返回错误:列引用“seat”不明确 UPDATE new_table nt SET nt.seat = ot.seat FROM old_table ot WHERE ot.id

我正在更改我的db模式,并将列“seat”从旧的\u表移动到新的\u表。首先,我在新表中添加了一个“seat”列。现在我尝试用旧表中的值填充该列

UPDATE new_table
SET seat = seat
FROM old_table
WHERE old_table.id = new_table.ot_id;
返回错误:列引用“seat”不明确

UPDATE new_table nt
SET nt.seat = ot.seat
FROM old_table ot
WHERE ot.id = nt.ot_id;
返回错误:关系“new_table”的列“nt”不存在


想法?

IIRC要更新的表格是不能使用别名的表格。你试过这个吗

UPDATE new_table
SET seat = ot.seat
FROM old_table ot
WHERE ot.id = ot_id;

IIRC要更新的表不能有别名。你试过这个吗

UPDATE new_table
SET seat = ot.seat
FROM old_table ot
WHERE ot.id = ot_id;

你应该可以只提到
座位
,就像这样

UPDATE new_table nt
SET seat = ot.seat
FROM old_table ot
WHERE ot.id = nt.ot_id;

你应该可以只提到
座位
,就像这样

UPDATE new_table nt
SET seat = ot.seat
FROM old_table ot
WHERE ot.id = nt.ot_id;

我认为这不是特定于PostgreSQL,而是标准SQL我认为这不是特定于PostgreSQL,而是标准SQL