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

fix(tsql): Transpile standalone exp.Fetch LIMIT #4680

Merged
merged 1 commit into from
Jan 29, 2025
Merged

Conversation

VaggelisD
Copy link
Collaborator

Fixes #4665

Dialects like Oracle can FETCH directly from a result set:

oracle>  WITH t AS (SELECT 1 AS col UNION SELECT 2 AS col UNION SELECT 3 as col) 
SELECT * FROM t FETCH FIRST 2 ROWS ONLY;

col
1
2

T-SQL has the concept of OFFSET-FETCH which are defined under an ORDER BY clause. Thus, a possible transpilation is the following:

tsql> WITH t AS (SELECT 1 AS col UNION SELECT 2 AS col UNION SELECT 3 AS col) 
SELECT * FROM t AS ROWS ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH FIRST 2 ROWS ONLY

col
1
2

Docs

T-SQL OFFSET-FETCH | Oracle FETCH

@VaggelisD VaggelisD merged commit 69680c1 into main Jan 29, 2025
7 checks passed
@VaggelisD VaggelisD deleted the vaggelisd/tsql_fetch branch January 29, 2025 17:01
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

Successfully merging this pull request may close these issues.

Oracle Read Dialect Does not Transpile FETCH FIRST N ROWS ONLY
2 participants