1. Often there is a situation where you have a base table, and you need to organize access to only
part of the records of this table. The best practice is to use secure views.
use role accountadmin;
create or replace share stocks_share;
show shares;
grant usage on database samples to share stocks_share;
grant usage on schema samples.finance to share stocks_share;
grant select on table samples.finance.stocks_data to share
stocks_share;
show grants to share stocks_share;
alter share stocks_share add accounts=<consumer_account>;
create database shared_db from share <provider_ account>.STOCKS_SHARE;
In some extreme cases for a large volume of data, we might use physical devices such as AWS
Snowball or Azure Data Box.
A specialty of the technical design of the Snowflake is that the data is stored in micro-partitions,1
which are immutable. This means that with any operations such as the addition or deletion of
data, a new micro-partition is created, and the old one ceases to exist. Using special commands
that extend standard SQL, you can easily access historical data.
Data retention for enterprise and level above is 90 days. For transient object, it’s a day. For
standard edition, it’s a day.
The parameter DATA_RETENTION_TIME_IN_DAYS can be set on the whole account or on the
object level, meaning database, schema, or table. According to this hierarchy, the parameter can
be overridden.
The statement SELECT with AT/BEFORE
• The user can request the version of the table by specifying the exact time (using keyword
TIMESTAMP)
SELECT * FROM <table> AT (TIMESTAMP => 'Mon, 05 Aug 2019 13:30:00 -0700'::timestamp);
For example, select historical data from a table of 30 minutes ago using this:
SELECT * FROM <table> AT (offset -60*30)
SELECT * FROM <table> BEFORE (STATEMENT => '<statement_id>');
show parameters like '%DATA_RETENTION%' in account;
alter account set DATA_RETENTION_TIME_IN_DAYS = 2;
show parameters like '%DATA%_RETENTION' in database samples;
alter database samples set DATA_RETENTION_TIME_IN_DAYS = 1;
create table samples.finance.stocks_10m clone samples.finance.stocks at (offset => -10*60);
Here 60 is second.
TIMESTAMP Alias for one of the TIMESTAMP variations (TIMESTAMP_NTZ by default).
TIMESTAMP_LTZ TIMESTAMP with local time zone; time zone, if provided, is not stored.
TIMESTAMP_NTZ TIMESTAMP with no time zone; time zone, if provided, is not stored.
TIMESTAMP_TZ TIMESTAMP with time zone.
Snowflake treats 'NaN' as greater than any other FLOAT value, including infinity.
The maximum length is 16 MB (uncompressed) for varchar. The maximum length is 8 MB for binary.
2. Synonymous with VARCHAR, except that if the length is not specified, CHAR(1) is the default.
Snowflake currently deviates from common CHAR semantics in that strings shorter than the maximum
length are not space-padded at the end.
'string with a ' character' = $$string with a ' character$$
select to_date ('2019-02-28') + INTERVAL '1 day, 1 year';
+---------------------------------------------------+
| TO_DATE ('2019-02-28') + INTERVAL '1 DAY, 1 YEAR' |
|---------------------------------------------------|
| 2020-03-01 |
+---------------------------------------------------+
select to_date('2018-04-15') + 1;
+---------------------------+
| TO_DATE('2018-04-15') + 1 |
|---------------------------|
| 2018-04-16 |
+---------------------------+
When we create a database, two schemas are auto created. Information_Schema
and Public. Information_Schema stores metadata about database like table,
sequence, views, procedure, functions, pipes and so on.
You can resize a warehouse size on the fly when it’s running. USE_WAREHOUSE command to
change warehouse in SQL editor.
// and -- is comment in Snowsql.
Multi cluster warehouse is also called elastic cluster.
3.
4.
5.
6. Snowflake is HIPPA, SOC 1, 2 PCI DSS and FedRmap ready.
When you choose a cloud, you choose which provider your Snowflake account sits on top of. However, after
choosing your infrastructure provider, you do not interact with the cloud provider and you are not charged by the
min the management of your Snowflake account. Uses Azure storage and compute resources behind the scenes.
Uses AWS storage and compute resources behind the scenes. Uses GCP storage and compute resources
behind the scenes. With Snowflake, you interact only with the Service layer. The Service layer interacts with
Compute and Storage layers, which in turn interact with the underlying cloud infrastructure provider. Snowflake
Account Options & Assurances Cloud Platform Provider.
With Snowflake, you interact only with the Service layer. The Service layer interacts with Compute and Storage
layers, which in turn interact with the underlying cloud infrastructure provider. Generally speaking, customers will
want to choose a region close to their point of service. This reduces latency.
Availability Zones are replications of data within a region that are used to ensure that data is always available to
end users, even if one copy of the data becomes unavailable. Snowflake maintains data recovery and failsafe in
addition to the assurances provided by the cloud provider’s availability zone designs.
The Business Critical Edition adds encryption for all network movements and metadataSnowflake offers
continuous data protection.
Snowflake accounts use cloud availability zones for failover.
Snowflake accounts are easily replicated for regional failover
Snowflake accounts are easily replicated for cloud-provider failover
7. GCP was given as a cloud choice in 2020 (early)..
The SNOWFLAKEdatabase contains information about account usage. It is automatically added by Snowflake to
each new account. It is sometimes called the “Account Usage Share” because it is shared by Snowflake so
customers can check usage.
The SNOWFLAKE_SAMPLE_DATA is also shared by Snowflake. This database allows for performance testing
and tutorials. Customers are not charged for storing this data., because they are NOT storing it. The database is
a shared database.
13. If two users have fired the same query(with exact same text) and if their roles (like public, sysadmin) are same,
the data will be retrieved from result cache.
14. In VPC edition, sqls are also encypted. All keys are rotated annually.
15.
16. History for load file – 64 days. History for snowpipe -14 days.
Variant & varchar can store upto 16 mb. Binary can do till 8 mb.
Unloading data only supports delimited (CSV etc), JSON and Parquet.