in reply to Re^2: SQL::Statement limit clause with placeholders
in thread SQL::Statement limit clause with placeholders

In SQL::Statement there are two kinds of LIMIT clauses -those that can be applied during a search and those that can only be applied afterwards. Strictly speaking, a LIMIT clause without an ORDER BY clause makes no sense since it depends on the physical ordering of rows (which nothing ever should). But given the way S::S operates, I allow it to do LIMIT without ORDER BY since that's the only way to actually limit what is being searched as distinct from limiting a result set after a search.
  • Comment on Re^3: SQL::Statement limit clause with placeholders

Replies are listed 'Best First'.
Re^4: SQL::Statement limit clause with placeholders
by jhourcle (Prior) on Jun 03, 2005 at 15:23 UTC

    Although it's not typical, there are times when I find the use of a limit, without the use of ORDER BY to be very useful--

    If you're attempting to get the field that will be returned by a query (typically because of stuff like 'SELECT * FROM table'), adding a limit is useful, but you can also just throw in 'WHERE 0=1'.

    If you're attempting to clear a queue of some sort, where it doesn't need to be FIFO or otherwise processed in some particular order, but you can't have it run for too long. (so you can work in 500 record sets, rather than working on the whole queue at once) I found this very useful in Oracle, when I'd have to limit my processing time for each transaction so I didn't exceed my rollback segments as the system tried to maintain transactional consistency. (and unfortunately, due to the nature of the problem, I couldn't just set the transaction SERIALIZABLE ... I might've been able to use a autonomous transaction, though)

    So, in most situations, I agree that it doesn't make sense, but there are times when it does, and it probably has more to do with how the programmer thinks about the problem more than anything else -- there are other working solutions for the examples that I've given above, but using limits without ordering in those situations makes sense to me.