I have already used GENERATED ALWAYS AS
when creating new tables. However, when I try to UPDATE TABLE
an already existing table with this computed/generated column I keep on getting a 1064 error. I have also tried with the ALTER TABLE
option, but haven`t had any success either.
Sample:
UPDATE TABLE crecimiento_pib
SET País GENERATED ALWAYS AS (CONCAT(CountryName,' ',CountryCode));
Thanks for the help you can provide!
CodePudding user response:
If you are trying to add a computed column to an existing table, the syntax is:
ALTER TABLE crecimiento_pib
ADD COLUMN País varchar(200) GENERATED ALWAYS AS (CONCAT(CountryName, ' ', CountryCode));
with an appropriate size defined by the length of the CountryName
and CountryCode
columns (which you haven't shown).