Skip to main content

streams

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

Overview

Namestreams
TypeResource
Idsnowflake.tables.streams

Fields

The following fields are returned by SELECT queries:

successful

NameDatatypeDescription
namestringName of the stream (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
database_namestringDatabase in which the stream is stored (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
schema_namestringSchema in which the stream is stored (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
table_namestringTable name whose changes are tracked by the stream (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
commentstringuser comment associated to an object in the dictionary
created_onstring (date-time)Date and time when the stream was created.
invalid_reasonstringReason why the stream cannot be queried successfully. This column supports future functionality. Currently, the only value returned is N/A.
modestringMode of the stream. Possible values include: APPEND_ONLY, INSERT_ONLY. For streams on tables, the column displays DEFAULT.
ownerstringRole that owns the stream (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
owner_role_typestringThe type of role that owns the stream (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
stalebooleanSpecifies whether the stream is stale or not
stale_afterstring (date-time)Timestamp when the stream became stale or may become stale if not consumed.
stream_sourceobjectSource for the stream
typestringType of the stream; currently DELTA only.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectdatabase_name, schema_name, name, endpointFetch a stream
listselectdatabase_name, schema_name, endpointlike, startsWith, showLimit, fromNameList streams
createinsertdatabase_name, schema_name, endpoint, name, stream_sourcecreateMode, copyGrantsCreate a stream
deletedeletedatabase_name, schema_name, name, endpointifExistsDelete a stream
cloneexecdatabase_name, schema_name, name, targetDatabase, targetSchema, endpoint, namecreateMode, copyGrantsClone a stream

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 identifier (orgname-accountname) (default: orgname-accountname)
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.
targetDatabasestringDatabase of the target resource. Defaults to the source's database
targetSchemastringSchema of the target resource. Defaults to the source's schema
copyGrantsbooleanParameter to enable copy grants when creating the object.
createModestringParameter 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.
fromNamestringParameter 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.
ifExistsbooleanParameter 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.
likestringParameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.
showLimitintegerParameter to limit the maximum number of rows returned by a command.
startsWithstringParameter 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

Fetch a stream

SELECT
name,
database_name,
schema_name,
table_name,
comment,
created_on,
invalid_reason,
mode,
owner,
owner_role_type,
stale,
stale_after,
stream_source,
type
FROM snowflake.tables.streams
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND name = '{{ name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
;

INSERT examples

Create a stream

INSERT INTO snowflake.tables.streams (
name,
stream_source,
comment,
database_name,
schema_name,
endpoint,
createMode,
copyGrants
)
SELECT
'{{ name }}' /* required */,
'{{ stream_source }}' /* required */,
'{{ comment }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}',
'{{ copyGrants }}'
RETURNING
status
;

DELETE examples

Delete a stream

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

Lifecycle Methods

Clone a stream

EXEC snowflake.tables.streams.clone
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@name='{{ name }}' --required,
@targetDatabase='{{ targetDatabase }}' --required,
@targetSchema='{{ targetSchema }}' --required,
@endpoint='{{ endpoint }}' --required,
@createMode='{{ createMode }}',
@copyGrants={{ copyGrants }}
@@json=
'{
"name": "{{ name }}",
"comment": "{{ comment }}"
}'
;