PostgreSQL DELETE FROM(SELECT * FROM table FETCH FIRST 10 ROWS ONLY)

前端之家收集整理的这篇文章主要介绍了PostgreSQL DELETE FROM(SELECT * FROM table FETCH FIRST 10 ROWS ONLY)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在postgresql中只删除几行?
我想在子查询获取删除的10行.

我的桌子

您需要根据您的要求使用where条件,如下所示:
delete from mytable where id in(1,2,3,4,5,6,7,8,9,10)

要么

delete from mytable where id in(select id from mytable where someconditon)

或者如果你想使用ctid删除前10名,你可以尝试这样做:

DELETE FROM mytable 
WHERE ctid IN (
    SELECT ctid
    FROM mytable 
    GROUP BY s.serialId,s.valuetimestamp
    ORDER BY s.serialId
    LIMIT 10
)

如果您要从表中删除重复项,请尝试以下操作:

DELETE FROM mytable
 WHERE ctid NOT IN
  (SELECT MAX(s.ctid)
    FROM table s
    GROUP BY s.serialId,s.valuetimestamp);

猜你在找的Postgre SQL相关文章