Low-level building block for generating SQL from R expressions. Strings are escaped; names become bare SQL identifiers. User infix functions have % stripped.

sql_expr(x, con = sql_current_con())

Arguments

x

A quasiquoted expression

con

An optional database connection to control the details of the translation. The default, NULL, generates ANSI SQL.

Examples

sql_expr(f(x + 1))
#> <SQL> F(x + 1.0)
sql_expr(f("x", "y"))
#> <SQL> F('x', 'y')
sql_expr(f(x, y))
#> <SQL> F(x, y)
sql_expr(cast("x" %as% DECIMAL))
#> <SQL> CAST('x' AS DECIMAL)
sql_expr(round(x) %::% numeric)
#> <SQL> ROUND(x) :: numeric