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

Support lambda expressions #153

Closed
apstndb opened this issue Oct 19, 2024 · 0 comments · Fixed by #219
Closed

Support lambda expressions #153

apstndb opened this issue Oct 19, 2024 · 0 comments · Fixed by #219

Comments

@apstndb
Copy link
Contributor

apstndb commented Oct 19, 2024

Lambda expressions have not yet been supported.

Syntax

https://cloud.google.com/spanner/docs/reference/standard-sql/functions-reference#lambdas

(arg[, ...]) -> body_expression
arg -> body_expression

Examples

https://cloud.google.com/spanner/docs/reference/standard-sql/array_functions#array_filter

SELECT
  ARRAY_FILTER([1 ,2, 3], e -> e > 1) AS a1,
  ARRAY_FILTER([0, 2, 3], (e, i) -> e > i) AS a2;

/*-------+-------*
 | a1    | a2    |
 +-------+-------+
 | [2,3] | [2,3] |
 *-------+-------*/

https://cloud.google.com/spanner/docs/reference/standard-sql/array_functions#array_includes

SELECT
  ARRAY_INCLUDES([1, 2, 3], e -> e > 3) AS a1,
  ARRAY_INCLUDES([1, 2, 3], e -> e > 0) AS a2;

/*-------+------*
 | a1    | a2   |
 +-------+------+
 | false | true |
 *-------+------*/

https://cloud.google.com/spanner/docs/reference/standard-sql/array_functions#array_transform

SELECT
  ARRAY_TRANSFORM([1, 2, 3], e -> e + 1) AS a1,
  ARRAY_TRANSFORM([1, 2, 3], (e, i) -> e + i) AS a2;

/*---------+---------*
 | a1      | a2      |
 +---------+---------+
 | [2,3,4] | [1,3,5] |
 *---------+---------*/

Reference

https://cloud.google.com/spanner/docs/release-notes#March_21_2023

The following functions and expressions have been added to the GoogleSQL dialect:

FYI

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 a pull request may close this issue.

1 participant