sql_parse: Parse SQL into an abstract syntax tree

View source: R/parse.R

sql_parseR Documentation

Parse SQL into an abstract syntax tree

Description

Parse SQL into an abstract syntax tree

Usage

sql_parse(sql, dialect = "generic")

Arguments

sql

A single character string with one or more SQL statements (separated by ⁠;⁠).

dialect

Dialect used for parsing.

Value

A polyglot_ast object: a list with elements

  • statements — a list with one nested-list AST per statement;

  • sql — the input SQL;

  • dialect — the dialect used.

Each AST node is a named list; the name of the outer element gives the node kind (e.g. "select"). The structure follows the upstream polyglot-sql JSON AST format and round-trips through sql_generate().

Examples

ast <- sql_parse("SELECT a, b FROM t WHERE x = 1")
ast
names(ast$statements[[1]])

polyglotSQL documentation built on Sept. 27, 2026, 5:06 p.m.