How to get catalog and schema from system query table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 08:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 10:59 AM
Thanks for the response. Do you know if there is a way to do that programmatically? Either through an API or a system table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:26 AM
Ok thank you. I appreciate the help. It does not seem currently possible to get all of the data I need.