0% found this document useful (0 votes)
6 views1 page

SQL Queries To Fetch Query History

The document provides SQL queries to retrieve query history from a database session, including options to filter by session, warehouse, user, and specific time ranges. It includes commands to fetch the last 100 queries, queries from the past hour, and queries within a specified 30-minute block over the past week. Additionally, it allows for filtering by usernames using a LIKE condition.

Uploaded by

tokixit492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

SQL Queries To Fetch Query History

The document provides SQL queries to retrieve query history from a database session, including options to filter by session, warehouse, user, and specific time ranges. It includes commands to fetch the last 100 queries, queries from the past hour, and queries within a specified 30-minute block over the past week. Additionally, it allows for filtering by usernames using a LIKE condition.

Uploaded by

tokixit492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

-- Retrieve up to the last 100 queries run in the current session:

select *
from table(information_schema.query_history_by_session())
order by start_time;

select *
from table(information_schema.query_history_by_warehouse())
order by start_time;

select *
from table(information_schema.query_history_by_user())
order by start_time;

-- include a condition on username


select *
from table(information_schema.query_history_by_user())
where user_name like 'KASHISH%'
order by start_time;

-- Retrieve up to the last 100 queries run by the current user (or run by any user
on any warehouse on which the current user has the MONITOR privilege):

select *
from table(information_schema.query_history())
order by start_time;

-- Retrieve up to the last 100 queries run in the past hour by the current user
-- (or run by any user on any warehouse on which the current user has the MONITOR
privilege):

select *
from table(information_schema.query_history(dateadd('hours',-
1,current_timestamp()),current_timestamp()))
order by start_time;

-- Retrieve all queries run by the current user (or run by any user on any
warehouse on which the current user has the MONITOR privilege)
-- within a specified 30 minute block of time within the past 7 days:

select *
from table(information_schema.query_history(
end_time_range_start=>to_timestamp_ltz('2020-09-11 12:00:00.000 -0700'),
end_time_range_end=>to_timestamp_ltz('2020-09-24 12:30:00.000 -0700')));

You might also like