cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Querying columns with special characters

JamieN
New Contributor III

I'm trying to do a select on a column with special characters in Databricks sql.

I've tried the following

%sql
select ex$col 
from database.table
limit 10;
 
%sql
select `ex$col `
from database.table
limit 10;

They both don't work and will return "ex does not exist. Did you mean the following/ .... "

Is there a way to do this? or is the functionality not currently supported?

1 ACCEPTED SOLUTION

Accepted Solutions

JamieN
New Contributor III

Many thanks for your reply.

Ah, we are creating the table using a delta location

 
s = f"create table {database}.{dataset_name} using delta location '{location}'"
spark.sql(s)

I can still query the special character using pyspark which good for me now, but a lot of our users will want to use sql. The only option seems to be to change the schema.

View solution in original post

4 REPLIES 4

LandanG
Databricks Employee
Databricks Employee

It might depend on how your table was created. I was able to get the below to work:

CREATE OR REPLACE TABLE database.special_chars (`ex$col` int);
INSERT INTO database.special_chars VALUES (1);
 
SELECT `ex$col`
FROM database.special_chars
LIMIT 10;

JamieN
New Contributor III

Many thanks for your reply.

Ah, we are creating the table using a delta location

 
s = f"create table {database}.{dataset_name} using delta location '{location}'"
spark.sql(s)

I can still query the special character using pyspark which good for me now, but a lot of our users will want to use sql. The only option seems to be to change the schema.

@LandanG . The issue is with %sql .

Anonymous
Not applicable

Hi @Jamie Nathan​ 

Hope all is well!

Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

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