snowflake.core.view.ViewCollection | Snowflake Documentation (original) (raw)

class snowflake.core.view.ViewCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[ViewResource]

Represents the collection operations on the Snowflake View resource.

With this collection, you can create, iterate through, and search for views that you have access to in the current context.

Examples

Creating a view instance:

views = root.databases["my_db"].schemas["my_schema"].views new_view = View( ... name="my_view", ... columns=[ ... ViewColumn(name="col1"), ViewColumn(name="col2"), ViewColumn(name="col3"), ... ], ... query="SELECT * FROM my_table", ... ) views.create(new_view)

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(view: View, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → ViewResource

Create a view in Snowflake.

Parameters:

Examples

Creating a view, replacing any existing view with the same name:

views = root.databases["my_db"].schemas["my_schema"].views new_view = View( ... name="my_view", ... columns=[ ... ViewColumn(name="col1"), ViewColumn(name="col2"), ViewColumn(name="col3"), ... ], ... query="SELECT * FROM my_table", ... ) views.create(new_view, mode=CreateMode.or_replace)

create_async(view: View, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → PollingOperation[ViewResource]

An asynchronous version of create().

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

items() → ItemsView[str, T]

iter(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None, deep: Annotated[bool, Strict(strict=True)] | None = None) → Iterator[View]

Iterate through View objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:

Examples

Showing all views that you have access to see:

views = view_collection.iter()

Showing information of the exact view you want to see:

views = view_collection.iter(like="your-view-name")

Showing views starting with ‘your-view-name-‘:

views = view_collection.iter(like="your-view-name-%")

Using a for loop to retrieve information from iterator:

for view in views: ... print(view.name, view.query)

iter_async(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None, deep: Annotated[bool, Strict(strict=True)] | None = None) → PollingOperation[Iterator[View]]

An asynchronous version of iter().

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

keys() → KeysView[str]

values() → ValuesView[T]