简体   繁体   中英

AWS Redshift - Define column as a conditional?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM