Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Snowflake: query_history_by_user() does not yield expected result

Snowflake provides the QUERY_HISTORY_BY_USER() function to actually see the queries from any user. I’m using this command for querying:

select * from table (
  <DATABASE>.<SCHEMA>.query_history_by_user(
    USER_NAME=>'myUser',
    END_TIME_RANGE_START=>to_timestamp_ltz('2021-11-24 06:00:00 -0100'),
    END_TIME_RANGE_END=>to_timestamp_ltz('2021-11-24 17:00:00 -0100'),
    RESULT_LIMIT=>100)
);

The problem is that this query does not yield any results. However, if I start the same query without the USER_NAME=>'myUser' statement – which is semantically the same, since the executing user is taken as a default – I do get the expected result. The result for a different user than mine (i.e. USER_NAME=>'differentUser') is also empty. All queries are executed as ACCOUNTADMIN, so rights are presumably not the problem.

So the question is: why does the query work without any user provided but does not work with a user specified?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help is really appreciated!

>Solution :

I sugest wrapping user name with ": USER_NAME=>'differentUser' => USER_NAME=>'"differentUser"'

QUERY_HISTORY_BY_USER

A string specifying a user login name or CURRENT_USER. Only queries run by the specified user are returned. Note that the login name must be enclosed in single quotes.

Also, if the login name contains any spaces, mixed-case characters, or special characters, the name must be double-quoted within the single quotes (e.g. ‘"User 1"’ vs ‘user1’).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading