Support SQL standard `OVERLAY(... PLACING ... FROM ... FOR ...)` syntax by Daedalus-Icarus · Pull Request #101681 · ClickHouse/ClickHouse · GitHub
Skip to content

Support SQL standard OVERLAY(... PLACING ... FROM ... FOR ...) syntax#101681

Merged
alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
Daedalus-Icarus:overlay-sql-syntax
Apr 10, 2026
Merged

Support SQL standard OVERLAY(... PLACING ... FROM ... FOR ...) syntax#101681
alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
Daedalus-Icarus:overlay-sql-syntax

Conversation

@Daedalus-Icarus

@Daedalus-Icarus Daedalus-Icarus commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

…FOR length])` syntax

Add parser-level syntactic sugar for the SQL standard OVERLAY function syntax. The overlay function already exists; this adds support for the keyword-based form using PLACING, FROM, and FOR as separators, matching PostgreSQL, Oracle, and DuckDB behavior.

Both overlay and overlayUTF8 support the new syntax. The existing comma-separated functional form continues to work unchanged.

Closes #99604

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add parser-level syntactic sugar for the SQL standard OVERLAY function syntax. The overlay function already exists; this adds support for the keyword-based form using PLACING, FROM, and FOR as separators.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.769

…FOR length])` syntax

Add parser-level syntactic sugar for the SQL standard `OVERLAY` function
syntax. The `overlay` function already exists; this adds support for the
keyword-based form using `PLACING`, `FROM`, and `FOR` as separators,
matching PostgreSQL, Oracle, and DuckDB behavior.

Both `overlay` and `overlayUTF8` support the new syntax. The existing
comma-separated functional form continues to work unchanged.

Closes ClickHouse#99604
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member

The failures of "Flaky check" in "functions_bad_arguments" will be fixed by #101994.

Comment thread src/Parsers/ExpressionListParsers.cpp Outdated

if (state == 1)
{
if (ParserToken(TokenType::Comma).ignore(pos, expected)

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.

OverlayLayer currently accepts mixed separator styles (PLACING/FROM keywords interleaved with commas), because each separator check is comma || keyword independently.

This makes malformed SQL-standard forms execute as valid functional calls, e.g. OVERLAY('abcdef' PLACING 'XY', 3) gets parsed and executed as overlay('abcdef', 'XY', 3) instead of being rejected.

Please lock the syntax mode after the first separator (keyword mode vs comma mode) and only accept the corresponding separator family in subsequent states.

Comment thread src/Parsers/ExpressionListParsers.cpp Outdated

/// Allow closing bracket in any state so that calls with too few arguments
/// (e.g. overlay('a', 'b')) are rejected by the function, not the parser.
if (!finished && ParserToken(TokenType::ClosingRoundBracket).ignore(pos, expected))

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.

ClosingRoundBracket is accepted unconditionally in any state. In the SQL-standard form this allows missing mandatory FROM to slip through parsing.

Concrete case: OVERLAY('abcdef' PLACING 'XY') currently parses as overlay('abcdef', 'XY') and fails only with NUMBER_OF_ARGUMENTS_DOESNT_MATCH, while the query is syntactically invalid and should be rejected at parse time.

Please allow early ) only for the legacy comma form where it is intentional; for keyword mode, require FROM before accepting a closing bracket.

…yntax

Address review feedback:
- Track keyword_mode vs comma_mode after the first separator
- In keyword mode, only accept PLACING/FROM/FOR keywords
- In comma mode, only accept commas
- In keyword mode, require FROM before allowing closing bracket
- Add negative test cases for mixed syntax rejection
…tations

Syntax errors from the parser are caught client-side by clickhouse-client
before the query reaches the server, so `clientError` is the correct
annotation for these test cases.
@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 92.00% (92/100) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

@alexey-milovidov alexey-milovidov self-assigned this Apr 10, 2026
@alexey-milovidov alexey-milovidov added this pull request to the merge queue Apr 10, 2026
Merged via the queue into ClickHouse:master with commit aa6ff58 Apr 10, 2026
163 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 10, 2026
@rschu1ze

Copy link
Copy Markdown
Member

@Desel72 Please add documentation for OVERLAY here.

@rschu1ze

Copy link
Copy Markdown
Member

@Desel72 Please add documentation for OVERLAY here.

@Daedalus-Icarus

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support OVERLAY(string PLACING replacement FROM start FOR length) function

4 participants