Skip to main content

System Functions in Snowflake gives you the option to check your Snowflake instance and have information about it. All system functions have the syntax as SYSTEM$…. It can be a function call without any parameters or if you need you can add it into () after ‘$‘ sign.

There are 3 main types of System Functions:

  • Control Functions
  • Information Functions
  • Query Information Functions

Control Functions

Functions that allow you to execute certain immediate system changing actions such as cancelling a query or cancelling all queries. You can try these functions by yourself:

SELECT SYSTEM$CANCEL_ALL_QUERIES;                       --> cancel all queries

SELECT SYSTEM$CANCEL_QUERY( <query_id> );               --> cancel the query that you specified by id

SELECT SYSTEM$ABORT_SESSION( <session_id> );            --> abort session that you specified by id

CALL SYSTEM$WAIT(  <amount>, [<time_unit>] );           --> by default time_unit is SECONDS, this function is executed with 'CALL' syntax

These functions, as you can see, allow us to make certain actions on our Snowflake instance. There are many other options for these types of functions. You can find them from here.

Information Functions

Functions that return information about system. There are a lot of options for these types of functions, they range from functions that return you the type of the value you give as a paramter to functions that precalculate the search optimazation cost!

First you can try to run these codes in your Snowflake instance and then we will talk about the more interesting ones:

SELECT SYSTEM$TYPEOF( <any_object> );                                                  --> returns the type of the object

SELECT SYSTEM$CLUSTERING_INFORMATION( '<table_name>' , [ '(column, column, ...)']);        --> returns the clustering information about a specific table

SELECT SYSTEM$CLUSTERING_DEPTH( '<table_name>' , [ '(column, column, ...)']);             --> returns the clustering depth of a specific table

SELECT SYSTEM$GET_TAG( '<tag_name>' , '<obj_name>' , '<obj_domain>' );                    --> returns the tag of specified object

SELECT SYSTEM$GENERATE_SCIM_ACCESS_TOKEN('<integration_name>');                       --> generates a token for your integration, VALID FOR 6 MONTHS

SELECT SYSTEM$ESTIMATE_SEARCH_OPTIMIZATION_COSTS('<table_name>' [ , '<search_method_with_target>' ]);                             --> returns all of the details about search optimazation + if it is not enabled, how much will be the cost

SELECT SYSTEM$DATABASE_REFRESH_HISTORY(  ['<secondary_db_name>'] )                          --> returns the refresh history for database

As I mentioned before there are a lot of options on Information Functions, the ones about clustering information and depth are really interesting in my opinion. They give you the opportunity to see what’s happening behind the system.

I would say that ESTIMATE_SEARCH_OPTIMIZATION_COSTS() is another very interesting function. You should keep in mind that to use this function you must have your Snowflake instance as Enterprise or higher. It shows you the details and the cost informaiton about search optimizaton before you create it, so you can decide it afterwards to execute or not.

Query Information Functions

Functions that return information about queries. For example information about EXPLAIN plans.

You can run these examples on your Snowflake instance:

SELECT *
    FROM TABLE(GET_QUERY_OPERATOR_STATS(LAST_QUERY_ID()));          --> returns stats for that query operator

SELECT * SYSTEM$ESTIMATE_QUERY_ACCELERATION( '<query_id>' );          --> estimates query acceleration

Conclusion

There are many interesting System Functions in Snowflake and some of them can take your experience in Snowflake to another level. Using these functions may impact your work in a very professional and controlable way. Please don’t forget to check out this link for the full list of System Functions. Thank you for reading my article.


Auteur

  • Can Hobek

    Hello, my name is Can Höbek. I am originally from Turkey, and I currently live in Milan. In my second year of high school, I did a year of exchange in Turin to prepare myself for university and improve my Italian language. I am currently in my final year of bachelor degree in Politecnico di Torino in Management Engineering. During my time there, I was involved in various extracurricular activities, such as volunteer organizations that make science laboratories for primary school students with specific topics that point towards the 2030 goals , which helped me to develop my ability to work in a team and developed my soft-skills. From primary school up to last year of high school, for 10 years I went to conservatory school specializing in classic guitar. I always loved to play different instruments even though my professionality is on classic guitar. Another part that creates me is sports; I love all types of sports but I played professionally in some teams as a football, volleyball player. Before my last year of university I had started to think about my interests and did some research on how to improve myself on that. I found myself wanting to improve on the data and programming part that I started to learn in my first years of university. When I was doing these researches, I found Nimbus that offers first a formation on specific topics that was my area of interest and then gives us an opportunity to work on some projects that you have had formation. The most important part for me was to feel myself learning new things in my area of interest and then working on it.

Can Hobek

Hello, my name is Can Höbek. I am originally from Turkey, and I currently live in Milan. In my second year of high school, I did a year of exchange in Turin to prepare myself for university and improve my Italian language. I am currently in my final year of bachelor degree in Politecnico di Torino in Management Engineering. During my time there, I was involved in various extracurricular activities, such as volunteer organizations that make science laboratories for primary school students with specific topics that point towards the 2030 goals , which helped me to develop my ability to work in a team and developed my soft-skills. From primary school up to last year of high school, for 10 years I went to conservatory school specializing in classic guitar. I always loved to play different instruments even though my professionality is on classic guitar. Another part that creates me is sports; I love all types of sports but I played professionally in some teams as a football, volleyball player. Before my last year of university I had started to think about my interests and did some research on how to improve myself on that. I found myself wanting to improve on the data and programming part that I started to learn in my first years of university. When I was doing these researches, I found Nimbus that offers first a formation on specific topics that was my area of interest and then gives us an opportunity to work on some projects that you have had formation. The most important part for me was to feel myself learning new things in my area of interest and then working on it.