3 weeks ago - last edited 3 weeks ago
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:
With these limitations, is it even possible to achive this?
Any input is appriciated.
3 weeks ago
have you tried without backticks? I mean using common variable substitution:
ALTER TABLE my_table OWNER TO '${new_owner}' (new_owner is a dab var of course).
3 weeks ago
I have tried that, it will result in single quotes being wrapped around the variable value and cause a syntax error
3 weeks ago
how does your variables section look like?
Perhaps something you have tried but what if you use backticks instead of the single quotes in the query.
The var is substituted with the value (the value itself does not contains backticks though!).
3 weeks ago
The variable looks like this in the yml file:
admin_group: azure_admin_group_dev
This will return the value like this:
'azure_admin_group_dev'
If I add the backticks in as part of the value like this:
admin_group: '`azure_admin_group_dev`'
The value will be returned like this:
'`azure_admin_group_dev`'
Unfortunatly, none of these values are acceptable in the OWNER TO statement. It needs to be returned like this:
`azure_admin_group_dev`
3 weeks ago
ugh,
SQL... 🙂
tried to escape the backticks in the yml? so \`group\`?
3 weeks ago
Yea, still no luck. I might start looking into refactoring the scripts into notebooks and be done with it.
Using backslash in yml (admin_group: \`azure_admin_group_dev\`) will return:
'\\`azure_admin_group_dev\\`'
3 weeks ago
I guess that is a safe bet.
Good luck!
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now