sql_validate: Validate SQL

View source: R/parse.R

sql_validateR Documentation

Validate SQL

Description

Checks that SQL parses in the given dialect and, optionally, applies stricter syntax rules, semantic lint warnings, and schema-aware checks.

Usage

sql_validate(sql, dialect = "generic", ...)

Arguments

sql

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

dialect

Dialect used for parsing.

...

Additional validation options:

  • strict_syntax — reject non-canonical syntax the parser would accept for compatibility (e.g. trailing commas before FROM); default FALSE.

  • semantic — report query-quality warnings (W001–W004, e.g. ⁠SELECT *⁠ mixed with explicit columns) and semantic correctness errors (E230–E232: ungrouped columns, misplaced aggregates and misplaced window functions). The errors invalidate the statement even when strict_syntax = FALSE; default FALSE.

  • schema — a schema specification (see as_polyglot_schema()); enables unknown-table/column, type and reference checks.

  • error — if TRUE, raise a polyglot_validation_error instead of returning an invalid result; default FALSE.

Value

A polyglot_validation object: a list with valid (logical) and errors (data frame with columns severity, code, message, line, column).

Examples

sql_validate("SELECT a FROM t")
sql_validate("SELECT FROM WHERE")
v <- sql_validate("SELECT a, FROM t", strict_syntax = TRUE)
v$valid

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