-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(sqlite): support INSERT IGNORE and offset-only limits [CODEX] #7674
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,18 @@ def _generated_to_auto_increment(expression: exp.Expr) -> exp.Expr: | |
| return expression | ||
|
|
||
|
|
||
| def _offset_to_limit(expression: exp.Expr) -> exp.Expr: | ||
| if not isinstance(expression, exp.Select): | ||
| return expression | ||
|
|
||
| offset = expression.args.get("offset") | ||
|
|
||
| if offset and not expression.args.get("limit"): | ||
| expression.limit(-1, copy=False) | ||
|
|
||
| return expression | ||
|
|
||
|
|
||
| class SQLiteGenerator(generator.Generator): | ||
| SELECT_KINDS: tuple[str, ...] = () | ||
| TRY_SUPPORTED = False | ||
|
|
@@ -152,6 +164,7 @@ class SQLiteGenerator(generator.Generator): | |
| exp.Rand: rename_func("RANDOM"), | ||
| exp.Select: transforms.preprocess( | ||
| [ | ||
| _offset_to_limit, | ||
| transforms.eliminate_distinct_on, | ||
| transforms.eliminate_qualify, | ||
| transforms.eliminate_semi_and_anti_joins, | ||
|
|
@@ -182,6 +195,13 @@ class SQLiteGenerator(generator.Generator): | |
|
|
||
| LIMIT_FETCH = "LIMIT" | ||
|
|
||
| def insert_sql(self, expression: exp.Insert) -> str: | ||
| if expression.args.get("ignore"): | ||
| expression.set("ignore", False) | ||
| expression.set("alternative", "IGNORE") | ||
|
|
||
|
Comment on lines
+199
to
+202
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... this is fine for now, but looks like a code smell to me. Having two ways to represent the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch here. let me think about a better way to do this
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine for now, let's not deal with it in this PR. Just wanted to leave a note for future reference. |
||
| return super().insert_sql(expression) | ||
|
|
||
| def bitwiseandagg_sql(self, expression: exp.BitwiseAndAgg) -> str: | ||
| self.unsupported("BITWISE_AND aggregation is not supported in SQLite") | ||
| return self.function_fallback_sql(expression) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's gate any logic in this transformation with an instance check: