09-09-2024 03:45 AM
It's not possible to use the ALTER TABLE tblname OWNER TO serviceprinc1 command in Azure Databricks, as this isn't supported. I was trying to set a catalog table's ownership, but it resulted in an error. How can I achieve this using a script
09-09-2024 04:08 AM
Hi @Nid-cbs ,
Are you sure that you're using correct syntax? According to documentation it should be:
ALTER TABLE table_name SET OWNER TO principal
09-09-2024 05:32 AM
ALTER TABLE catalogue.schema.table OWNER TO GUID
the rror is [PARSE_SYNTAX_ERROR] Syntax error at or near 'OWNER'.(line 1, pos 43)
09-09-2024 05:38 AM
I still think that you're using bad synxtax. You're missing SET keyword before OWNER. Try as below:
ALTER TABLE catalogue.schema.table SET OWNER TO GUID
09-09-2024 05:47 AM
Thanks. Still the same error
[PARSE_SYNTAX_ERROR] Syntax error at or near 'OWNER'.(line 1, pos 35)
09-09-2024 06:54 AM - edited 09-09-2024 06:57 AM
Hi @Nid-cbs ,
It depends on how you are using the code.
Make sure you are using .sql notebook type or %sql magic command, and not spark.sql.
Also, the owner should be wrapped in ` backtick characters:
%sql
ALTER TABLE test_table SET OWNER TO `owner`
More on that:
https://stackoverflow.com/questions/68804903/databricks-alter-table-owner-to-userid-is-not-working-w...
09-09-2024 09:19 AM
it turns out that The ALTER TABLE statement in Databricks SQL does not support changing the owner of a table directly.It seems we need to use REST API to do the same
09-09-2024 09:51 AM
Thanks for the information. This is very strange though. I'll check it tommorrow. It should work in a notebook with %sql cell.
It won't work if use spark.sql("ALTER TABLE test_table SET OWNER TO `owner_name`") though.
Tuesday
I was getting same error in python notebook and I found typo in my sql:
Changing from
ALTER TABLE table_name SET OWNER TO 'principal'
to below fixed the issue.
ALTER TABLE table_name SET OWNER TO `principal`
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