Support `OVERLAY(string PLACING replacement FROM start FOR length)` function · Issue #99604 · ClickHouse/ClickHouse · GitHub
Skip to content

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

Description

@qoega

Summary

ClickHouse does not support the OVERLAY function, which replaces a substring within a string at a specified position and length. It is part of the standard SQL string function set and is supported by PostgreSQL, Oracle, DuckDB, and others. See the PostgreSQL documentation on string functions for reference.

Current Behavior

SELECT OVERLAY('Hello World' PLACING 'SQL' FROM 7 FOR 5);
-- Code: 62. DB::Exception: Syntax error

Expected Behavior

SELECT OVERLAY('Hello World' PLACING 'SQL' FROM 7 FOR 5);
-- Returns: 'Hello SQL'

SELECT OVERLAY('abcdef' PLACING 'XY' FROM 3 FOR 2);
-- Returns: 'abXYef'

-- Without FOR clause — replaces exactly length(replacement) characters:
SELECT OVERLAY('abcdef' PLACING 'XY' FROM 3);
-- Returns: 'abXYef'

-- Empty replacement = deletion:
SELECT OVERLAY('Hello World' PLACING '' FROM 6 FOR 6);
-- Returns: 'Hello'

Semantics: OVERLAY(s PLACING r FROM p FOR n)concat(substring(s, 1, p-1), r, substring(s, p+n)).

Workaround

SELECT concat(
    substring('Hello World', 1, 6),
    'SQL',
    substring('Hello World', 12)
);

Version info

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions