cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to get catalog and schema from system query table

jen-metaplane
New Contributor II

Hi,

We are querying the system.query table to parse query history. If the table in the query is not fully qualified with its catalog and schema, how can we derive the catalog and schema?

Thanks,

Jen

4 REPLIES 4

filipniziol
Contributor

Hi @jen-metaplane ,

if the table in the query is not fully qualified, then the system resolves it using the default calatog and schema.

You need to identify what were the default catalog and schema during query execution.

Thanks for the response. Do you know if there is a way to do that programmatically? Either through an API or a system table?

filipniziol
Contributor

There is no straightforward method to get this data. 

Run the query to check the defaults:

SELECT
  current_catalog() AS default_catalog,
  current_schema() AS default_schema;

Catalog and schema may be changed in the query, so if you have query text you need to search whether "USE CATALOG" or "USE" were used. If no "USE" is in the text, you may assume that the defaults were used.

filipniziol_0-1726769048872.png

 

Ok thank you. I appreciate the help. It does not seem currently possible to get all of the data I need.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group