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: 

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
Esteemed Contributor

The correct syntax would be:

SELECT 'Goal' AS Type, Value 
FROM table

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