简体   繁体   中英

How to restrict only 1 row to get updated in postgres?

I am trying to convert the below Oracle sql to 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.

在此处输入图片说明

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.

Thanks in advance..

You can use the pseudo column CTID here -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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