SQL¶
LATERAL FLATTEN(similar toUnNest) for flattening XML or JSON dataALTER SCHEMA X SWAP Yswaps schemas, eg dev with prod- time-travel specify with
ATorBEFOREand time as:TIMESTAMP:select * from my_table at(timestamp => '2021-01-01 16:20:00.0700'::timestamp)OFFSET:select * from my_table at(offset => -60*5)STATEMENT: query-idselect * from my_table before(statement => '2333333-33499-3432')
UNDROP {TABLE,SCHEMA,DATABASE} x- use
SHOW {TABLE,SCHEMA,DATABASE} HISTORYto see all versions within retention - to
UNDROPversions before the latest one, undrop and rename until the desired version is reached
- use
VARIANTfor loading semi-structured (eg JSON) or OBJECT or ARRAY dataCREATE STAGE TEST_STAGE URL='s3://bucket/path1/path2/to create external staging area- primary key, unique index, foreign key and not null are supported, but only not null is enforced
TRUNCATE TABLEremoves load metadata, thus allowing same file to be loaded againTOP nalways returns the same results, whereasLIMITandFETCHreturn the same results only ifORDER BYis specified- Accessing JSON variant columns:
- use
col:<element>, column name is case-insensitive, but element names are not - JSON objects can be referenced either by dot or bracket notation. E.g.
col:elem.sub_elemorcol['elem']['sub_elem'] - JSON arrays can be referenced by bracket notation. E.g.
col:elem[0]
- use
SHOW GRANTS ON {<type> <obj>|ACCOUNT}: show all privileges granted on the objectSHOW GRANTS TO ROLE ...: show all privileges granted to the role.SHOW GRANTS OF ROLE ...: show users and roles that have been granted this roleTXN_MAX_WAITERSandTXN_MAX_TABLE_LOCK_WAITERSlimit outstanding write requests on a single table to 20 by default.VARIANTcolumn can be up to 16MB binary encoded (but uncompressed otherwise)- Schema level
FUTURE GRANTtakes precedence and overrides any database-levelFUTURE GRANTs
Multi table INSERT¶
- conditional:
insert all when <cond> then into ... - unconditional:
insert all into ...
Admin¶
| action | affects | who | notes |
|---|---|---|---|
system$abort_transaction |
running transactions | user or AccountAdmin |
show transactions or show locks |
system$abort_session |
active session | AccountAdmin |
|
system$cancel_query |
running query | 1 | |
system$cancel_all_queries |
all session queries | 1 | |
alter warehouse .. abort ... |
all running queries on WH | ||
alter user .. abort ... |
all running queries of user | ||
alter user .. ser disabled |
all running+future queries of user |
- User, user's owner, or
operateownershipon warehouse
Variables¶
set (a,b,c) = (1,2,3)- dereference values by
$egselect $a; show variablesto list all variables- SnowSQL variables are different from SQL variables.
- define
-D var=valueor!define var=value - Use
-o variable_substitution=trueand&<var>to access
- define