Using yml variables as table owner through SQL

AsgerLarsen
New Contributor III

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:

  1. The 'OWNER TO' SQL statement requires the value to be wrapped in backticks (``)
  2. The 'OWNER TO' SQL statement can't execute subqueries like e.g. (SELECT CONCAT('`',{{admin_group}},'`') as c)
  3. 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.
  4. 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.