How do I delete a fixed number of rows with sorting in PostgreSQL?

后端 未结 6 1515
予麋鹿
予麋鹿 2020-11-28 03:27

I\'m trying to port some old MySQL queries to PostgreSQL, but I\'m having trouble with this one:

DELETE FROM logtable ORDER BY timestamp LIMIT 10;

6条回答
  •  无人及你
    2020-11-28 03:56

    If you don't have a primary key you can use the array Where IN syntax with a composite key.

    delete from table1 where (schema,id,lac,cid) in (select schema,id,lac,cid from table1 where lac = 0 limit 1000);
    

    This worked for me.

提交回复
热议问题