title: How do I delete a fixed number of rows with sorting in PostgreSQL?
body: <p>I'm trying to port some old MySQL queries to PostgreSQL, but I'm having trouble with this one:</p>
  
  <pre><code>DELETE FROM logtable ORDER BY timestamp LIMIT 10;
  </code></pre>
  
  <p>PostgreSQL doesn't allow ordering or limits in its delete syntax, and the table doesn't have a primary key so I can't use a subquery. Additionally, I want to preserve the behavior where the query deletes <em>exactly</em> the given number or records -- for example, if the table contains 30 rows but they all have the same timestamp, I still want to delete 10, although it doesn't matter which 10.</p>
  
  <p>So; how do I delete a fixed number of rows with sorting in PostgreSQL?</p>
  
  <p><em>Edit:</em> No primary key means there's no <code>log_id</code> column or similar. Ah, the joys of legacy systems!</p>