Skip to contents

Renders a sql_parse() result back into SQL text using the target dialect's syntax rules (keywords, quoting, literals). Note this is plain generation: unlike sql_transpile(), it does not apply cross-dialect function rewrites (e.g. IFNULL is not converted to COALESCE). Use it to render programmatically-built or modified ASTs; use sql_transpile() for full dialect translation.

Usage

sql_generate(ast, dialect = "generic")

Arguments

ast

A polyglot_ast object from sql_parse() (or sql_annotate_types()).

dialect

Target dialect for rendering.

Value

A character vector with one element per statement in the AST.

Examples

ast <- sql_parse("SELECT a, b FROM t WHERE x = 1")
sql_generate(ast, dialect = "postgres")
#> [1] "SELECT a, b FROM t WHERE x = 1"