in_schema: Refer to a table in another schema/catalog

View source: R/schema.R

in_schemaR Documentation

Refer to a table in another schema/catalog

Description

in_schema() and in_catalog() can be used to refer to tables outside of the current catalog/schema. However, we now recommend using I() as it's typically less typing.

Usage

in_schema(schema, table)

in_catalog(catalog, schema, table)

Arguments

catalog, schema, table

Names of catalog, schema, and table. These will be automatically quoted; use sql() to pass a raw name that won't get quoted.

Examples

# Previously:
in_schema("my_schema", "my_table")
in_catalog("my_catalog", "my_schema", "my_table")
in_schema(sql("my_schema"), sql("my_table"))

# Now
I("my_schema.my_table")
I("my_catalog.my_schema.my_table")
I("my_schema.my_table")

# Example using schemas with SQLite
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

# Add auxiliary schema
tmp <- tempfile()
DBI::dbExecute(con, paste0("ATTACH '", tmp, "' AS aux"))

library(dplyr, warn.conflicts = FALSE)
copy_to(con, iris, "df", temporary = FALSE)
copy_to(con, mtcars, I("aux.df"), temporary = FALSE)

con %>% tbl("df")
con %>% tbl(I("aux.df"))

dbplyr documentation built on May 29, 2024, 6:19 a.m.