Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expressions in LIMIT and OFFSET #1948

Closed
cpcloud opened this issue Jul 22, 2023 · 0 comments
Closed

Support expressions in LIMIT and OFFSET #1948

cpcloud opened this issue Jul 22, 2023 · 0 comments

Comments

@cpcloud
Copy link
Contributor

cpcloud commented Jul 22, 2023

Is your feature request related to a problem? Please describe.

LIMIT and OFFSET queries with scalar subquery expressions fail to parse.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I'd like these to parse successfully.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I've considered executing SQL and inlining the result, but that seems suboptimal given the support
in SQL for it.

Additional context

I'm testing with the duckdb dialect.

In [13]: import sqlglot as sg

In [14]: sg.__version__
Out[14]: '17.6.0'

In [15]: sg.parse_one("select * from t limit (select count(*) from t)", read="duckdb")
...
ParseError: Required keyword: 'expression' missing for <class 'sqlglot.expressions.Limit'>. Line 1, Col: 29.
  select * from t limit (select count(*) from t)

Similarly for offset:

In [16]: sg.parse_one("select * from t offset (select count(*) from t)", read="duckdb")
...
ParseError: Required keyword: 'expression' missing for <class 'sqlglot.expressions.Offset'>. Line 1, Col: 24.
  select * from t offset (select count(*) from t)

Both are supported using DuckDB:

D create or replace table t as select unnest(range(10)) as x;
D table t;
┌───────┐
│   x   │
│ int64 │
├───────┤
│     0 │
│     1 │
│     2 │
│     3 │
│     4 │
│     5 │
│     6 │
│     7 │
│     8 │
│     9 │
└───────┘
D select * from t limit (select count(*) - 5 from t);
┌───────┐
│   x   │
│ int64 │
├───────┤
│     0 │
│     1 │
│     2 │
│     3 │
│     4 │
└───────┘
D select * from t offset (select count(*) - 5 from t);
┌───────┐
│   x   │
│ int64 │
├───────┤
│     5 │
│     6 │
│     7 │
│     8 │
│     9 │
└───────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant