Skip to content

Add support for DuckDB LAMBDA keyword syntax - #2149

Merged
alamb merged 7 commits into
apache:mainfrom
lovasoa:duckdb-lambda-keyword-syntax
Jan 13, 2026
Merged

Add support for DuckDB LAMBDA keyword syntax#2149
alamb merged 7 commits into
apache:mainfrom
lovasoa:duckdb-lambda-keyword-syntax

Conversation

@lovasoa

@lovasoalovasoa commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for parsing DuckDB's LAMBDA keyword syntax for lambda functions.

DuckDB supports two syntaxes for lambda functions:

  • Arrow syntax: x -> x + 1 (already supported, but deprecated in duckdb)
  • Lambda keyword syntax: lambda x : x + 1 (preferred syntax in duckdb, added in this PR)

Initially reported in sqlpage/SQLPage#1171

Changes

  • Added LAMBDA keyword to keywords list
  • Added LambdaSyntax enum to track which syntax style was used (for correct round-tripping)
  • Added parse_lambda_expr() to parse lambda <params> : <expr> syntax
  • Updated LambdaFunction struct to include syntax field
  • Added tests for DuckDB lambda functions

Examples

-- Single parameterSELECT list_filter([1, 2, 3], lambda x : x >1)
-- Multiple parameters (with index)SELECT list_filter([1, 3, 1, 5], lambda x, i : x > i)
-- Method call syntaxSELECT [3, 4, 5, 6].list_filter(lambda x : x >4)

Test plan

  • Added test_duckdb_lambda_function test covering single param, multi-param, and method call syntax
  • All existing lambda tests pass (Databricks, ClickHouse, common)
  • All DuckDB tests pass

🤖 Generated with Claude Code and and reviewed by me, @lovasoa, a human.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@lovasoa

Copy link
Copy Markdown
ContributorAuthor

Hi @iffyio, @alamb ! Do you think you could have a look at this ? The old duckdb lambda syntax is deprecated, so I suppose this is going to pop out more and more. This comes from a bug report in sqlpage.

Comment threadsrc/ast/mod.rs
Comment threadtests/sqlparser_duckdb.rs Outdated
@alamb

Copy link
Copy Markdown
Contributor

(thanks for the review @iffyio )

lovasoaand others added 5 commits January 13, 2026 14:02
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
GenericDialect does not support lambda functions due to syntax conflicts with PostgreSQL JSON operators (specifically the '->' operator). This commit updates test_duckdb_lambda_function to verify lambda syntax only against DuckDbDialect, resolving a test failure where GenericDialect misparsed the lambda expression.
@lovasoa

Copy link
Copy Markdown
ContributorAuthor

@iffyio@alamb thanks for the review! I addressed your comments.

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- than yuou @lovasoa and @iffyio

@alamb
alamb added this pull request to the merge queueJan 13, 2026
Merged via the queue into apache:main with commit 3880a93Jan 13, 2026
10 checks passed
@lovasoa
lovasoa deleted the duckdb-lambda-keyword-syntax branch January 21, 2026 10:19
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Feb 3, 2026
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
fmguerreiro pushed a commit to fmguerreiro/datafusion-sqlparser-rs that referenced this pull request Feb 20, 2026
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Sign up for freeto 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.

3 participants

@lovasoa@alamb@iffyio