Skip to content

feat(duckdb): transpile bigquery's BYTES variant of REPLACE#6312

Merged
georgesittas merged 3 commits intomainfrom
tori/transpile-replace
Nov 12, 2025
Merged

feat(duckdb): transpile bigquery's BYTES variant of REPLACE#6312
georgesittas merged 3 commits intomainfrom
tori/transpile-replace

Conversation

@toriwei
Copy link
Collaborator

@toriwei toriwei commented Nov 12, 2025

BigQuery's REPLACE() can be used like STRING --> STRING and BYTES --> BYTES. DuckDB's REPLACE() only supports STRING --> STRING. This PR allows casts the byte arguments to strings (if the types are known/annotated).

BigQuery:
SELECT REPLACE(CAST('apple pie' AS BYTES), CAST('pie' AS BYTES), CAST('cobbler' AS BYTES)) AS bytes

Current DuckDB behavior:

SELECT REPLACE(CAST('apple pie' AS BLOB), CAST('pie' AS BLOB), CAST('cobbler' AS BLOB)) AS bytes

Binder Error:
No function matches the given name and argument types 'replace(BLOB, BLOB, BLOB)'. You might need to add explicit type casts.
        Candidate functions:
        replace(VARCHAR, VARCHAR, VARCHAR) -> VARCHAR


LINE 1: SELECT  REPLACE(CAST('apple pie' AS BLOB), CAST('pie' AS BLOB),...

After casting implementation:

D SELECT REPLACE(CAST(CAST('apple pie' AS BLOB) AS TEXT), CAST(CAST('pie' AS BLOB) AS TEXT), CAST(CAST('cobbler' AS BLOB) AS TEXT)) AS result;
┌───────────────┐
│    result     │
│    varchar    │
├───────────────┤
│ apple cobbler │
└───────────────┘

@toriwei toriwei requested a review from georgesittas November 12, 2025 00:50
@georgesittas
Copy link
Collaborator

Seems like a recurring pattern is emerging, see also: https://github.com/tobymao/sqlglot/pull/6240/files.

@toriwei toriwei force-pushed the tori/transpile-replace branch from f2086b3 to 98f8d2d Compare November 12, 2025 16:49
@georgesittas georgesittas changed the title fix(duckdb): cast binary arguments to varchar in REPLACE() feat(duckdb): transpile bigquery's BYTES variant of REPLACE Nov 12, 2025
@georgesittas georgesittas merged commit d170bbd into main Nov 12, 2025
7 checks passed
@georgesittas georgesittas deleted the tori/transpile-replace branch November 12, 2025 20:01
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 this pull request may close these issues.

3 participants