Select the tables in a database schema.
in_schema() selects the tables of a database that are in the schema schema= (as with analytics.customers, for the customers table in the analytics schema). When a Standard is applied to a database, the tables of its default schema are listed, as well as the tables of each schema named with in_schema() in the selector. A table outside the default schema is named with its schema (e.g., "analytics.customers") in the results.
The tables of a dictionary, a directory, or a list of files have no schema, so in_schema() selects none of them.
Parameters
schema: str
-
The name of the schema. It must match the database’s name of the schema exactly.
Returns
TableSelector
-
A table selector, which can be combined with other table selectors with
& (and), | (or), - (difference), and ~ (not), as in pb.in_schema("analytics") & pb.tbl_starts_with("dim_").
Examples
Let’s make a DuckDB database with a table in its default schema (main) and two in an analytics schema.
import ibis
import pointblank as pb
import polars as pl
con = ibis.duckdb.connect()
con.raw_sql("CREATE SCHEMA analytics")
con.create_table("orders", pl.DataFrame({"id": [1, 2]}))
con.create_table("customers", pl.DataFrame({"id": [1, 2]}), database="analytics")
con.create_table("products", pl.DataFrame({"id": [1, 2]}), database="analytics")
analytics_standard = pb.Standard(
name="analytics-keys",
steps=[pb.Step("rows_distinct", columns_subset="id")],
applies_to=pb.in_schema("analytics"),
)
analytics_standard.find_tables(con)
['analytics.customers', 'analytics.products']
Only the tables of the analytics schema are selected, and they’re named with their schema.