I was wondering if it is possible to create a new column from an existing column in the bush.
Say I have a table People (name string, age int)and I want to add a column is_old stringthat will be defined as if(age > 70, 'old', 'not_old'). Is there any way to do this?
The only way I can imagine now is to create a new table People_tempfrom the old one, delete the old table and rename the new table as follows:
create table People_new as select name, age, if(age > 70, 'old', 'not_old') as is_old from People;
drop table People;
alter table People_new rename People;
** Is there a way to do this without creating a temporary table?
(for example, the oracle has the idea of ββcomputed columns.)
source
share