โ02-27-2023 03:12 PM
It seems that due to how Databricks processes SQL cells, it's impossible to escape the $ when it comes to a column name.
I would expect the following to work:
%sql
SELECT 'hi' `$id`
The backticks ought to escape everything. And indeed that's exactly what Databricks thinks should happen, too. I was able to create a table outside of SQL commands (from a Dataframe) that had a column called $id . When I did a SHOW CREATE on that table, Databricks suggested using `$id` .
But what seems to happen is that Databricks seizes upon the sight of any $X to do Query Snippeting. So I end up with a blank column name instead.
Query Snippets only seem to respect the \ character as a means of escaping. But this does not bode well in conjunction with the backtick all-encompassing escape method, as the backticks will interpret the \ character literally, leaving me with a fieldname of \$id .
Does anyone have a workaround? If not, how can this be raised to a bug report? Thanks.
โ02-28-2023 11:09 AM
Thank you @Patrick Mascariโ for bringing this to our attention, the appropriate engineering and product team is aware of the issue and will prioritize it accordingly to be addressed in the future. There is no ETA that can be provided at this time.
In the mean time, consider the following work arounds:
โ02-28-2023 02:55 AM
Hi @Patrick Mascariโ , Just to understand the issue, you have a column named "$id" in your table and when you do "select $id from table" then it is failing. Is my understanding correct?
โ02-28-2023 05:51 AM
Hi @Patrick Mascariโ can you try by using the SQL() function, I have written the code below with an example please check if that works for you.
You can extract any escaped sequence in the column
data = spark.createDataFrame([("Alberto", 101),
("Dakota", 202),
("Kumar", 330),
("Siva", 4),
("Sree", 5),
("Kavin", 6)],
["Name", "$id"])
data.createOrReplaceTempView("temp_table")
sql("select `$id` as id, name from temp_table").show()
โ02-28-2023 08:52 AM
I want to build a table using the CREATE TABLE statement in Databricks SQL. But I can't name the column $id because `$id` does not work (in spite of Databricks' SHOW CREATE saying it should)
I understand that I can probably work around this by swapping to python/scala to run a spark query. If that's the only resort, then Databricks surely has a bug that needs reported and resolved..
โ02-28-2023 09:01 AM
Thank you for engaging with us on Databricks Community!
When you say you are trying this in Databricks SQL, I do not understand why the create table command is not working for you. Please see my working example with $'s in the column names:
To further narrow down what you are facing. Please clarify if you are attempting this in the Databricks SQL persona in the UI via the SQL editor (like in my screenshot above), or in a Notebook within the Data Science & Engineering persona. Screenshots would be helpful to further understand.
โ02-28-2023 09:17 AM
โ02-28-2023 09:28 AM
Thank you for clarifying. I too see the same behavior and have brought this to the attention of our Notebook team to further investigate.
โ02-28-2023 11:09 AM
Thank you @Patrick Mascariโ for bringing this to our attention, the appropriate engineering and product team is aware of the issue and will prioritize it accordingly to be addressed in the future. There is no ETA that can be provided at this time.
In the mean time, consider the following work arounds:
โ12-07-2023 01:13 PM
wow
โ03-30-2023 10:37 PM
I am working with an imported cdc table.
I can select the column `__$operation` in the query editor but not in a SQL notebook.
This is so annoying.
โ08-02-2023 09:48 PM
Is this issue resolved?
โ08-08-2023 12:30 PM
This has not been resolved from what I can see. Databricks team, any progress updates here? Its been 6 months.
โ04-08-2024 04:24 AM
What is the status on this bug report? its been over a year now.
โ09-03-2024 07:15 AM
What is the status of this bug? This is affecting user experience.
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