Reputation: 1433
Is it possible to define a column by means of a conditional expression? And have it evaluated/populated upon the insert.
Example:
CREATE TABLE "time_of_year"
(
"year" (smallint)
,"month" (smallint)
,"season" (conditional {case expression} )
)
;
The case statement would be:
CASE "month"
WHEN "month" in (12,1,2) THEN 'winter'
WHEN "month" in (3,4,5) THEN 'spring'
WHEN "month" in (6,7,8) THEN 'summer'
ELSE 'fall'
END
If a record is then inserted with year = 2016 and month = 5, then season would self-populate with 'spring'
Is this possible in Redshift?
Upvotes: 0
Views: 265
Reputation: 14035
Nope, Redshift doesn't support any kind of trigger based defaults - only simple defaults can be used.
I would suggest using a view to add the conditional column.
Upvotes: 1