Skip to main content

views

Creates, updates, deletes, gets or lists a views resource.

Overview

Nameviews
TypeResource
Idsnowflake.view.views

Fields

The following fields are returned by SELECT queries:

A Snowflake view

NameDatatypeDescription
namestringName of the view
database_namestringDatabase in which the view is stored
schema_namestringSchema in which the view is stored
columnsarrayThe columns of the view
commentstringuser comment associated to an object in the dictionary
created_onstring (date-time)Date and time when the view was created.
kindstringKind of the view, permanent (default) or temporary
ownerstringRole that owns the view
owner_role_typestringThe type of role that owns the view
querystringQuery used to create the view
recursivebooleanWhether or not this view can refer to itself using recursive syntax withot requiring a CTE (common table expression)
securebooleanWhether or not this view is secure

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_viewsselectdatabase_name, schema_name, endpointlike, startsWith, showLimit, fromName, deepList views
fetch_viewselectdatabase_name, schema_name, name, endpointFetch a view
create_viewinsertdatabase_name, schema_name, endpointcreateMode, copyGrantsCreate a view
delete_viewdeletedatabase_name, schema_name, name, endpointifExistsDelete a view

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
database_namestringIdentifier (i.e. name) for the database to which the resource belongs. You can use the /api/v2/databases GET request to get a list of available databases.
endpointstringOrganization and Account Name (default: orgid-acctid)
namestringIdentifier (i.e. name) for the resource.
schema_namestringIdentifier (i.e. name) for the schema to which the resource belongs. You can use the /api/v2/databases/{database}/schemas GET request to get a list of available schemas for the specified database.
copyGrantsbooleanQuery parameter to enable copy grants when creating the object.
createModestringQuery parameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.
deepbooleanOptionally includes dependency information of the view.
fromNamestringQuery parameter to enable fetching rows only following the first row whose object name matches the specified string. Case-sensitive and does not have to be the full name.
ifExistsbooleanQuery parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn't exist.
likestringQuery parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.
showLimitintegerQuery parameter to limit the maximum number of rows returned by a command.
startsWithstringQuery parameter 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.

SELECT examples

List views

SELECT
name,
database_name,
schema_name,
columns,
comment,
created_on,
kind,
owner,
owner_role_type,
query,
recursive,
secure
FROM snowflake.view.views
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND like = '{{ like }}'
AND startsWith = '{{ startsWith }}'
AND showLimit = '{{ showLimit }}'
AND fromName = '{{ fromName }}'
AND deep = '{{ deep }}';

INSERT examples

Create a view

INSERT INTO snowflake.view.views (
data__name,
data__secure,
data__kind,
data__recursive,
data__columns,
data__comment,
data__query,
database_name,
schema_name,
endpoint,
createMode,
copyGrants
)
SELECT
'{{ name }}' --required,
{{ secure }},
'{{ kind }}',
{{ recursive }},
'{{ columns }}' --required,
'{{ comment }}',
'{{ query }}' --required,
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}',
'{{ copyGrants }}'
;

DELETE examples

Delete a view

DELETE FROM snowflake.view.views
WHERE database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND name = '{{ name }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}';