Allow dialects that use -> as an operator to support LAMBDA syntax - #2458
Open
adriangb wants to merge 4 commits into
Open
Allow dialects that use -> as an operator to support LAMBDA syntax#2458adriangb wants to merge 4 commits into
-> as an operator to support LAMBDA syntax#2458adriangb wants to merge 4 commits into
Conversation
adriangb
commented
Aug 26, 2026
Comment on lines
+558
to
+560
| fn supports_lambda_keyword_syntax(&self) -> bool { | ||
| self.supports_lambda_functions() | ||
| } |
Author
There was a problem hiding this comment.
One could argue for adding fn supports_lambda_arrow_syntax() as well, but I'd hold off until there is a concrete use case for enabling arrow syntax but not lambda syntax.
Exercises the capability the way a downstream crate would: derive a dialect from PostgreSqlDialect with `supports_lambda_keyword_syntax` overridden, then check that `LAMBDA x : x + 1` parses while `->` and `->>` keep parsing as JSON member access rather than lambda parameters. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
adriangb
commented
Aug 26, 2026
Comment on lines
+127
to
+128
| #[test] | ||
| fn test_lambda_keyword_syntax_on_postgres_derivative() { |
Author
There was a problem hiding this comment.
I'm split between this (the real regression test I want) and another test using a MyDialect in sqlparser_custom_dialect.rs that enables the two flags. Open to input.
adriangb
commented
Aug 26, 2026
Address review feedback: rather than parsing the `LAMBDA` spelling and the `->` operator as separate statements, parse one expression that uses both — a lambda whose body is a JSON access — which is the shape a PostgreSQL derivative actually cares about. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
supports_lambda_functions()gates two different spellings of the same feature:x -> x + 1LAMBDAkeyword form,LAMBDA x : x + 1Because they share one flag, a dialect cannot have one without the other. That
shuts out any dialect that already gives
->a meaning. PostgreSQL is theobvious case:
->is JSON member access, so turning the flag on silentlyreinterprets existing expressions rather than adding a capability.
Concretely, with the flag enabled,
a -> 'b'no longer parses as a binaryoperator. It parses as a lambda with parameter
aand body'b', becauseparse_prefixtreats any unreserved word followed by->as a lambdaparameter. Note
->>is unaffected, so the breakage is partial and easy tomiss.
The
LAMBDAkeyword form has no such conflict: it does not claim->.Change
Adds
Dialect::supports_lambda_keyword_syntax(), which gates only theLAMBDAkeyword form, and defaults to
supports_lambda_functions().No existing dialect changes behavior. Dialects that support the arrow form keep
both spellings; dialects that support neither still get neither. A dialect that
uses
->for something else can now override just the new method to get lambdaswithout disturbing its operator.
No dialect shipped here opts in; this only makes the capability reachable.
Tests
Two tests in
tests/sqlparser_custom_dialect.rs:supports_lambda_keyword_syntaxparseslambda x : x + 1while->stays aBinaryOperator::Arrowsupports_lambda_functionsstill accepts bothspellings, pinning the defaulting behavior
Full suite,
cargo fmt --check, andcargo clippy --all-targets --all-featuresall pass.