How to limit result set size for arbitrary query in Ingres?

笑着哭i 提交于 2019-12-01 20:13:17

问题


In Oracle, the number of rows returned in an arbitrary query can be limited by filtering on the "virtual" rownum column. Consider the following example, which will return, at most, 10 rows.

SELECT * FROM all_tables WHERE rownum <= 10

Is there a simple, generic way to do something similar in Ingres?


回答1:


Blatantly changing my answer. "Limit 10" works for MySql and others, Ingres uses

Select First 10 * from myTable

Ref




回答2:


select * from myTable limit 10 does not work.

Have discovered one possible solution:

    TIDs are "tuple identifiers" or row addresses.  The TID contains the
    page number and the index of the offset to the row relative to the
    page boundary.  TIDs are presently implemented as 4-byte integers.
    The TID uniquely identifies each row in a table.  Every row has a
    TID.  The high-order 23 bits of the TID are the page number of the page
    in which the row occurs.  The TID can be addressed in SQL by the name 
    `tid.'

So you can limit the number of rows coming back using something like:

select * from SomeTable where tid < 2048

The method is somewhat inexact in the number of rows it returns. It's fine for my requirement though because I just want to limit rows coming back from a very large result set to speed up testing.




回答3:


Hey Craig. I'm sorry, I made a Ninja Edit. No, Limit 10 does not work, I was mistaken in thinking it was standard SQL supported by everyone. Ingres uses (according to doc) "First" to solve the issue.




回答4:


Hey Ninja editor from Stockholm! No worries, have confirmed that "first X" works well and a much nicer solution than I came up with. Thankyou!



来源:https://stackoverflow.com/questions/49602/how-to-limit-result-set-size-for-arbitrary-query-in-ingres

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!