cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I create a column on the fly which would have same value for all rows in spark sql query

haseebkhan1421
New Contributor

I have a SQL query which I am converting into spark sql in azure databricks running in my jupyter notebook. In my SQL query, a column named Type is created on the fly which has value 'Goal' for every row:

SELECT Type='Goal', Value

FROM table

Now, when I am using the same syntax on the spark sql in my azure databricks notebook, it gives me an error:

Error in SQL statement: AnalysisException: cannot resolve '`Type`' given input columns:

How can I convert the same logic in azure databrick spark sql

1 REPLY 1

Ryan_Chynoweth
Honored Contributor III

The correct syntax would be:

SELECT 'Goal' AS Type, Value 
FROM table

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.