Documentation
Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

query_id

The query_id variable can be used in SQL Post-hook only and is the Snowflake query_id of the executed query.

Syntax

{{query_id}}

Example

Create flow with the single SQL Post-hook that uses query_id variable:

ube#COMPUTE_WH@(no database).(no schema)>CREATE OR REPLACE SUNDECK FLOW MY_FLOW
                                              POST HOOK TRACK_INSERT
                                              IF SQL_MATCHES('INSERT .*', 'i') THEN
                                              SQL {
                                                  'sqlText': 'INSERT INTO ube_db.public.inserts
                                                              VALUES(current_timestamp, 
                                                                     \'INSERT\', 
                                                                     \'{{query_id}}\')',
                                                  'errorBehavior' : 'BYPASS'
                                             }    
                                          ;

+------------------------------------------------------------------------------+
| status                                                                       |
|------------------------------------------------------------------------------|
| Flow MY_FLOW created. Use ‘DESCRIBE SUNDECK FLOW "MY_FLOW"’ for flow details |
+------------------------------------------------------------------------------+
1 Row(s) produced. 

Connect to it and run simple query that inserts a single row into some table:

ube#COMPUTE_WH@(no database).(no schema)>INSERT into ube_db.public.t1 values(100, 200);
+-------------------------+                                                     
| number of rows inserted |
|-------------------------|
|                       1 |
+-------------------------+
1 Row(s) produced. 

ube#COMPUTE_WH@(no database).(no schema)>select * from ube_db.public.inserts;
+-------------------------------+------------+--------------------------------------+
| INSERT_TIMESTAMP              | QUERY_TYPE | QUERY_ID                             |
|-------------------------------+------------+--------------------------------------|
| 2023-11-28 15:25:34.818 -0800 | INSERT     | 01b0a41d-0001-e9ac-0009-950700fc4832 |
+-------------------------------+------------+--------------------------------------+
1 Row(s) produced. 

Please note, that table ube_db.public.inserts was created prior to query execution.