
Answer-first summary for fast verification
Answer: GENERATED ALWAYS AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS INT)
Delta Lake supports generated columns, which automatically compute their values based on a user-specified function over other columns in the Delta table. For the `age` column to be correctly calculated from `dateOfBirth`, the correct syntax is `GENERATED ALWAYS AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS INT)`. This ensures the age is always computed as an integer based on the difference in days between the current date and the date of birth, divided by 365.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are tasked with creating a table named employees in Delta Lake with a calculated column age derived from the dateOfBirth column. The SQL code block provided is incomplete. Select the correct statement to fill in the blank for the SQL code to execute successfully.
A
GENERATED DEFAULT AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS FLOAT)
B
GENERATED ALWAYS AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS INT)
C
GENERATED DEFAULT AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS INT)
D
GENERATED ALWAYS AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS FLOAT)
E
GENERATED AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS FLOAT)
No comments yet.