Skip to contents

Schemas group the tables of a lake, and are the natural home for medallion layers (bronze, silver, gold) or per-study areas. Every function that takes a table name accepts "schema.table", and list_ducklake_tables() shows each table's schema. DuckLake writes a schema's data files under a directory of their own, which is what path-based access control on object storage keys on.

Usage

create_schema(schema_name, if_not_exists = TRUE, ducklake_name = NULL)

Arguments

schema_name

Name of the schema, or a dotted path for a nested one.

if_not_exists

When the schema already exists, say so and do nothing (default TRUE) rather than error.

ducklake_name

Optional name of the attached DuckLake catalog. If NULL, the current database is used.

Value

Invisibly, NULL.

Details

Schemas nest (DuckLake 1.1): "sales.europe" is the schema europe inside sales, and its tables are named "sales.europe.orders". Every dot in a name is a level, so the parents are created first when they are missing, and a table, schema, or schema_name argument anywhere in the package takes the same dotted path. A first component that names an attached lake is read as the lake ("lake.sales.orders"). One limit is DuckDB's rather than DuckLake's: COMMENT ON takes at most three qualifiers, so comments and variable labels reach a table one level deep and no deeper; create_table() warns and drops the labels of a deeper table. A lake on catalog format 1.0 has no nested schemas; see attach_ducklake(automatic_migration = ).

Examples

lake_dir <- tempfile("schema_lake_")
dir.create(lake_dir)
attach_ducklake("schema_lake", lake_path = lake_dir)

# One schema per medallion layer
create_schema("bronze")
#> Created schema "bronze".
create_schema("silver")
#> Created schema "silver".

create_table(mtcars, "bronze.cars")
get_ducklake_table("bronze.cars") |>
  dplyr::filter(cyl == 4) |>
  create_table("silver.cars")

list_ducklake_tables()
#>   schema_name table_name  type
#> 1      bronze       cars table
#> 2      silver       cars table

detach_ducklake("schema_lake", shutdown = TRUE)
unlink(lake_dir, recursive = TRUE)