如何限制 Ingres 中任意查询的结果集大小?

发布于 2024-07-04 12:14:27 字数 187 浏览 7 评论 0原文

在 Oracle 中,可以通过过滤“虚拟”rownum 列来限制任意查询中返回的行数。 考虑以下示例,它将最多返回 10 行。

SELECT * FROM all_tables WHERE rownum <= 10

有没有一种简单、通用的方法可以在 Ingres 中做类似的事情?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心房敞 2024-07-11 12:14:27

嘿克雷格。 抱歉,我做了一个忍者编辑。
不,Limit 10 不起作用,我错误地认为它是每个人都支持的标准 SQL。 Ingres 使用(根据文档)“First”来解决这个问题。

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.

深居我梦 2024-07-11 12:14:27

嘿来自斯德哥尔摩的忍者编辑! 不用担心,已经确认“first X”效果很好,并且是比我想出的更好的解决方案。 谢谢你!

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!

小猫一只 2024-07-11 12:14:27

公然改变我的答案。 “Limit 10”适用于 MySql 和其他,Ingres 使用

Select First 10 * from myTable

Ref

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

Select First 10 * from myTable

Ref

﹂绝世的画 2024-07-11 12:14:27

select * from myTable limit 10 不起作用。

发现了一种可能的解决方案:

    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.'

因此,您可以使用以下方法限制返回的行数:

select * from SomeTable where tid < 2048

该方法在返回的行数方面有些不精确。 不过,这适合我的要求,因为我只想限制从非常大的结果集返回的行以加快测试速度。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文