Run a query against a GlareDB database
Usage
glaredb_sql(query, connection = NULL)
glaredb_prql(query, connection = NULL)
glaredb_execute(query, connection = NULL)
Arguments
- query
A character of the query to run.
For
glaredb_sql()
andglaredb_execute()
, an SQL query.For
glaredb_prql()
, a PRQL query.
- connection
A GlareDB connection object or
NULL
. IfNULL
, the default in-memory database is used.
Value
A GlareDB execusion output (Query plan).
For glaredb_execute()
, the value is returned invisibly.
Examples
# You can materialize the query result by `as_glaredb_table()` etc.
glaredb_sql("SELECT 'hello from R' as hello") |>
as_glaredb_table()
#> ┌──────────────┐
#> │ hello │
#> │ ── │
#> │ Utf8 │
#> ╞══════════════╡
#> │ hello from R │
#> └──────────────┘
glaredb_prql("from [
{a=5, b=false},
{a=6, b=true},
]") |>
as.data.frame()
#> a b
#> 1 5 FALSE
#> 2 6 TRUE
# `glaredb_execute()` is useful for manipulating the database
glaredb_execute("CREATE TABLE my_table (a int)")
glaredb_execute("INSERT INTO my_table VALUES (1), (2)")
glaredb_sql("SELECT * FROM my_table") |>
as_glaredb_table()
#> ┌───────┐
#> │ a │
#> │ ── │
#> │ Int32 │
#> ╞═══════╡
#> │ 1 │
#> │ 2 │
#> └───────┘