
Ultimate access to all questions.
Answer-first summary for fast verification
Answer: ```sql CREATE FUNCTION combine_nyc(city STRING) RETURNS STRING RETURN CASE WHEN city = "brooklyn" THEN "new york" ELSE city END; ```
## Explanation Option **A** is the correct syntax for creating a SQL user-defined function (UDF) in Databricks: 1. **`CREATE FUNCTION`** - This is the standard SQL syntax for creating functions in Databricks SQL 2. **`RETURNS STRING`** - Properly declares the return type of the function 3. **`RETURN CASE ... END`** - Correctly uses the `RETURN` keyword followed by the CASE expression ### Why other options are incorrect: - **Option B**: Uses `CREATE UDF` which is not standard SQL syntax in Databricks - **Option C**: Uses `CREATE UDF` and missing `RETURNS STRING` declaration - **Option D**: Missing `RETURNS STRING` declaration after `CREATE FUNCTION` - **Option E**: Uses `CREATE UDF` which is not the standard syntax in Databricks SQL In Databricks SQL, the correct syntax follows ANSI SQL standards where you use `CREATE FUNCTION` to define scalar user-defined functions. The function body must return a value using the `RETURN` keyword, and the return type must be declared with `RETURNS <type>`.
Author: Keng Suppaseth
No comments yet.
A data engineer needs to apply custom logic to string column city in table stores for a specific use case. In order to apply this custom logic at scale, the data engineer wants to create a SQL user-defined function (UDF).
Which of the following code blocks creates this SQL UDF?
A
CREATE FUNCTION combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE FUNCTION combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
B
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
C
CREATE UDF combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE UDF combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
D
CREATE FUNCTION combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE FUNCTION combine_nyc(city STRING)
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
E
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;
CREATE UDF combine_nyc(city STRING)
RETURNS STRING
RETURN CASE
WHEN city = "brooklyn" THEN "new york"
ELSE city
END;