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

OFFSET and LIMIT get swapped in Trino Queries #1754

Closed
vadelaja opened this issue Jun 11, 2023 · 1 comment
Closed

OFFSET and LIMIT get swapped in Trino Queries #1754

vadelaja opened this issue Jun 11, 2023 · 1 comment
Assignees

Comments

@vadelaja
Copy link

vadelaja commented Jun 11, 2023

When transpiling a trino db query that contains both an offset and a limit, both values get swapped despite the fact that Trino throws an error if offset comes after limit and not before.

Running this:
sqlglot.transpile("SELECT a, b FROM test OFFSET 2 LIMIT 1", read="trino", write="trino") (offset in the correct location i.e. before limit)

Gives:
'SELECT a, b FROM test LIMIT 1 OFFSET 2' as output (limit and offset swapped)

And trino fails to run the new query with the error below:

Query 20230611_033140_00021_2zk4n failed: line 1:31: mismatched input 'OFFSET'. Expecting: <EOF>
SELECT a, b FROM test LIMIT 1 OFFSET 2

Basically, I'm trying to set the 'from' clause in an existing trino query using sqlglot.parse_one(query).from_("test_location").sql(dialect="trino"), but the OFFSET and LIMIT are swapped in the result.

@tobymao tobymao self-assigned this Jun 11, 2023
@tobymao
Copy link
Owner

tobymao commented Jun 11, 2023

seems like a bug in trino, but i can adjust this.

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
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

2 participants