snowflake.core.schema.SchemaCollection | Snowflake Documentation (original) (raw)

class snowflake.core.schema.SchemaCollection(database: DatabaseResource, root: Root)

Bases: DatabaseObjectCollectionParent[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 collection belongs to.

root

The Root object this collection belongs to.

Methods

create(schema: ModelSchemaModel, *, clone: str | Clone | None = None, mode: CreateMode = CreateMode.error_if_exists) → SchemaResource

Create a schema in Snowflake.

Parameters:

Examples

Creating a new schema called new_schema in my_db:

schemas = root.databases["my_db"].schemas new_schema_ref = schemas.create(Schema("new_schema"))

Creating a new schema called new_schema in my_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 in my_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 ... )

create_async(schema: ModelSchemaModel, *, clone: str | Clone | None = None, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[SchemaResource]

An asynchronous version of create().

Refer to PollingOperation for more information on asynchronous execution and the return type.

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:

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)

iter_async(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) → PollingOperation[Iterator[ModelSchemaModel]]

An asynchronous version of iter().

Refer to PollingOperation for more information on asynchronous execution and the return type.

keys() → KeysView[str]

values() → ValuesView[T]