Professional Documents
Culture Documents
By Poguttu
List databases in Snowflake
select database_name,
created as create_date,
database_owner,
comment
from information_schema.databases
order by database_name;
User List
select catalog_name as database, schema_name,
schema_owner, created, last_altered
from information_schema.schemata
where schema_name not in ('INFORMATION_SCHEMA', 'PUBLIC')
order by schema_name;
show users;
select "name", "login_name", "default_role", "last_success_login", "expires_at_time",from table(result_scan(
last_query_id()))
order by "name";
List of Table
select table_schema,
table_name,
created as create_date,
last_altered as modify_date
from information_schema.tables
where table_type = 'BASE TABLE'
order by table_schema,
table_name;
select table_schema,
table_name,
last_altered as modify_time
from information_schema.tables
where last_altered > DATEADD(DAY, -30, CURRENT_TIMESTAMP)
and table_type = 'BASE TABLE'
order by last_altered desc;
Compare default values of different columns with the same name in Snowflake database
with result as (
select col.table_schema || '.' || col.table_name as table_1,
col.column_default as default_1,
col.column_name,
cmp_col.column_default as default_2,
(cmp_col.table_schema || '.' || cmp_col.table_name) as table_2,
case when (col.table_schema || '.' || col.table_name) <
(cmp_col.table_schema || '.' || cmp_col.table_name)
then 1
else 0 end as duplicate
from information_schema.columns col
join information_schema.columns cmp_col
on cmp_col.column_name = col.column_name
and not (col.table_schema = cmp_col.table_schema
and col.table_name = cmp_col.table_name)
where (col.column_default <> cmp_col.column_default
or ((col.column_default is null and cmp_col.column_default is not null )
or (cmp_col.column_default is null
and col.column_default is not null)))
and col.table_schema not in ('INFORMATION_SCHEMA')
and cmp_col.table_schema not in ('INFORMATION_SCHEMA')
) select table_1,
default_1,
column_name,
default_2,
table_2
from result
where duplicate = 0
order by table_1, column_name;
List table default values in Snowflake
select table_schema,
table_name,
column_name,
column_default
from information_schema.columns
where column_default is not null
order by table_schema,
table_name, column_name
select query_text,
warehouse_name,
database_name,
schema_name,
user_name,
role_name,
execution_status,
error_code,
error_message,
start_time,
end_time
from table(information_schema.query_history_by_session(session_id))
order by start_time desc -- put session id here
limit 1;
Find queries executed in specific warehouse in Snowflake
select query_text,
warehouse_name,
database_name,
schema_name,
user_name,
role_name,
execution_status,
error_code,
error_message,
start_time,
end_time
from table(information_schema.QUERY_HISTORY_BY_WAREHOUSE('DATAHOUSE'))
order by start_time desc;