Parses sql with the from dialect and regenerates it in the to
dialect, rewriting functions, quoting, and constructs as needed
(e.g. MySQL IFNULL() becomes PostgreSQL COALESCE()).
Usage
sql_transpile(
sql,
from,
to,
pretty = FALSE,
unsupported = c("raise", "warn", "ignore")
)Arguments
- sql
A single character string with one or more SQL statements (separated by
;).- from
Source dialect name (see
sql_dialects()).- to
Target dialect name (see
sql_dialects()).- pretty
If
TRUE, pretty-print the output.- unsupported
How to handle constructs that cannot be represented in the target dialect:
"raise"(default) throws apolyglot_transpile_error;"warn"and"ignore"continue and return the closest supported translation (with"warn", upstream collects diagnostics but still returns a result).
Semantic limitations
Transpilation is syntactic and best-effort: identical syntax can still
behave differently across engines (implicit casts, collations, NULL
ordering, integer division, time zone handling...). Always test the
translated SQL against the target database before using it in production.