Using yml variables as table owner through SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2025 03:42 AM - edited 04-16-2025 03:43 AM
I'm trying to change the ownership of a table in the Unity Catalog created through a SQL script. I want to do this though code.
I'm using a standard databricks bundle setup, which uses three workspaces: dev, test and prod.
I have created a variable in the databricks.yml file, let's call it 'admin_group'.
The variable's value depends on the workspace, so if the code is being executed from the dev environment, the value would be 'azure_admin_group_dev', if the environment is test, the value would be 'azure_admin_group_test' etc.
I'm trying to pass this variable into the ALTER TABLE with the OWNER TO statement, so the executed result would look like this:
ALTER TABLE catalog_name.schema_name.table_name OWNER TO `azure_admin_group_dev`
Notice the backticks wrapped around the admin_group value.
I run into some issue because of certain limitations:
- The 'OWNER TO' SQL statement requires the value to be wrapped in backticks (``)
- The 'OWNER TO' SQL statement can't execute subqueries like e.g. (SELECT CONCAT('`',{{admin_group}},'`') as c)
- The .yml files, where the variable value is defined, doesn't allow for backticks unless singlequotes are wrapped around them, in which case the statement won't accept the value.
- I would very much like to be able to do this in an SQL file.
With these limitations, is it even possible to achive this?
Any input is appriciated.
- Labels:
-
Workflows