简体   繁体   English

如何限制只有 1 行才能在 postgres 中更新?

[英]How to restrict only 1 row to get updated in postgres?

I am trying to convert the below Oracle sql to postgres sql:我正在尝试将以下 Oracle sql 转换为 postgres sql:

Update Table_name set flag='U' WHERE id= 1 and ROWNUM < 2.

if the data in the table is some thing like如果表中的数据类似于

在此处输入图片说明

Then the query should update only one record as Unique like flag='U'.. and other records should not be effected.然后查询应该只将一条记录更新为 Unique like flag='U'.. 并且其他记录不应该受到影响。

在此处输入图片说明

Note:There is no unique key nor primary key on the table.注意:表上没有唯一键和主键。 I don't have access rights to create a constraint.我没有创建约束的访问权限。

Since ROWNUM is not available in postgres, I am not able to do convert this query into postgres.由于 ROWNUM 在 postgres 中不可用,我无法将此查询转换为 postgres。

Thanks in advance..提前致谢..

You can use the pseudo column CTID here -您可以在此处使用伪列CTID -

Update Table_name
   SET flag='U'
 WHERE CTID IN (SELECT CTID FROM Table_name WHERE id = 1 LIMIT 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM