snowflake.core.schema.SchemaCollectionΒΆ
- class snowflake.core.schema.SchemaCollection(database: DatabaseResource, root: Root)ΒΆ
Bases:
ObjectCollection
[SchemaResource
]Represents the collection operations on the Snowflake schema resource.
With this collection, you can create, iterate through, and search for schemas that you have access to in the current context.
Examples
Creating a schema instance:
>>> schemas = root.databases["my_db"].schemas >>> new_schema = Schema("my_schema") >>> schemas.create(new_schema)
Attributes
- databaseΒΆ
The DatabaseResource this schema belongs to.
- rootΒΆ
The Root object this schema belongs to.
Methods
- create(schema: ModelSchemaModel, *, clone: str | Clone | None = None, mode: CreateMode = CreateMode.error_if_exists) SchemaResource ΒΆ
Create a schema in Snowflake.
- Parameters:
schema (SchemaResource) β The
Schema
object, together with theSchema
βs properties: name; kind, comment, managed_access, retention_time, budget, data_retention_time_in_days, default_ddl_colaltion, log_level, pipe_execution_paused, max_data_extension_time_in_days, suspend_task_after_num_failures, trace_level, user_task_managed_initial_warehouse_size and user_task_timeout_ms are optional.clone (str, or Clone, optional) β Whether to clone an existing schema. An instance of
Clone
, or str of the name,None
if no cloning is necessary.mode (CreateMode, optional) β
One of the following enum values.
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the schema already exists in Snowflake. Equivalent to SQLcreate schema <name> ...
.CreateMode.or_replace
: Replace if the schema already exists in Snowflake. Equivalent to SQLcreate or replace schema <name> ...
.CreateMode.if_not_exists
: Do nothing if the schema already exists in Snowflake. Equivalent to SQLcreate schema <name> if not exists...
Default is
CreateMode.error_if_exists
.
Examples
Creating a new schema called
new_schema
inmy_db
:>>> schemas = root.databases["my_db"].schemas >>> new_schema_ref = schemas.create(Schema("new_schema"))
Creating a new schema called
new_schema
inmy_db
by cloning an existing schema:>>> schemas = root.databases["my_db"].schemas >>> new_schema_ref = schemas.create( ... "new_schema", ... clone = Clone(source="original_schema", point_of_time=PointOfTimeOffset(reference="at", when="-5")), ... mode = CreateMode.or_replace ... )
Creating a new schema called
new_schema
inmy_db
by cloning an existing schema in another database:>>> schemas = root.databases["my_db"].schemas >>> new_schema_ref = schemas.create( ... "new_schema", ... clone = Clone( ... source="another_database.original_schema", ... point_of_time=PointOfTimeOffset(reference="at", when="-5") ... ), ... mode = CreateMode.or_replace ... )
- items() ItemsView[str, T] ΒΆ
- iter(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) Iterator[ModelSchemaModel] ΒΆ
Iterate through
Schema
objects from Snowflake, filtering on any optional βlikeβ pattern.- Parameters:
like (str, optional) β A case-insensitive string functioning as a filter, with support for SQL wildcard characters (
%
and_
).starts_with (str, optional) β String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
limit (int, optional) β Limit of the maximum number of rows returned by iter(). The default is
None
, which behaves equivalently to show_limit=10000. This value must be between1
and10000
.from_name (str, optional) β Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.
Examples
Showing all schemas that you have access to see:
>>> schemas = db_ref.schemas.iter()
Showing information of the exact schema you want to see:
>>> schemas = db_ref.schemas.iter(like="your-schema-name")
Showing schemas starting with βyour-schema-name-β:
>>> schemas = db_ref.schemas.iter(like="your-schema-name-%")
Using a for loop to retrieve information from iterator:
>>> for schema in schemas: >>> print(schema.name, schema.query)
- keys() KeysView[str] ΒΆ
- values() ValuesView[T] ΒΆ