cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to escape column comments when adding them programmatically

JameDavi_51481
New Contributor III

I would like to add comments to all of our columns, programmatically. The only way I can find to do this is through SQL DDL - e.g. `alter table sometable alter column somecolumn comment 'some comment string`. However, I want to read this comment string from a YAML file, and protect against SQL injection. I cannot find a way to do this - if I use `alter table sometable alter column somecolumn comment :placeholder` I get a syntax error on the colon.

 

I know that e.g. special characters like single quotes work in comments, because I can edit and apply them manually - but it's not obvious how to do this with DDL when updating a table programmatically.

1 REPLY 1

brockb
Databricks Employee
Databricks Employee

Hi @JameDavi_51481 ,

I do not believe this is supported currently, please see this line in the Parameter Marker documentation:

> You must not reference a parameter marker in a DDL statement...
Ref: https://docs.databricks.com/en/sql/language-manual/sql-ref-parameter-marker.html#parameter-markers

Another consideration for you would be to manage the 'state' of your table (and table comments) using Terraform instead of a YAML file. Here's the documentation for the `databricks_sql_table` resource:
https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/sql_table

Alternatively, please do feel free to request this as a new feature at https://ideas.databricks.com 

Hope it helps.

Connect with Databricks Users in Your Area

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