Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.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
Postgresql选择行并更新列_Sql_Postgresql_Select_Sql Update - Fatal编程技术网

Postgresql选择行并更新列

Postgresql选择行并更新列,sql,postgresql,select,sql-update,Sql,Postgresql,Select,Sql Update,我有带where子句的SQL Select查询。例如 select * from table where status = 1 在选择时,如何用选定的行同时更新单个列?我想标记所选行,以避免在下一个循环中重新选择。比如: select * from table where status = 1; update table set proc = 1 where id in (select id from table where status = 1) 但此查询不会返回结果。使用returnin

我有带where子句的SQL Select查询。例如

select * from table where status = 1
在选择时,如何用选定的行同时更新单个列?我想标记所选行,以避免在下一个循环中重新选择。比如:

select * from table where status = 1; update table set proc = 1 where id in (select id from table where status = 1)

但此查询不会返回结果。

使用returning子句:

update table 
    set proc = 1 
where id in (select id from table where status = 1)
returning *;

(顺便说一句:我假设内部select实际上不是从同一个表中进行选择,因为该语句实际上没有意义,因为它可以用一个简单的
重写,其中status=1

只涉及一个表?顺便说一句:不要给你的表格命名
table
;发明一些其他的元语法名称。