How do I get the last accessed time stamp for the

2020-04-30 02:11发布

问题:

I want to get the last accessed timestamp for a table in the snowflake

回答1:

Not always ideal, but a quick way to find this for one-off questions is to use QUERY_HISTORY

SELECT START_TIME, * 
FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) 
WHERE QUERY_TEXT LIKE '%MYSCHEMA.MYTABLE%';

Update: Query to specifically get just the most recent query time. Have to filter out the QUERY_HISTORY queries themselves. This is not especailly fast, and does require that the role that's running this has access to all the relevant history.

SELECT MAX(START_TIME)
FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) 
WHERE QUERY_TEXT ILIKE '%CONFIG.PIPELINE_LOG%'
AND NOT QUERY_TEXT ILIKE '%INFORMATION_SCHEMA.QUERY_HISTORY%';