Is it possible to create a VIRTUAL GENERATED column on a table that references another VIRTUAL GENERATED column in the same table? Basically, I was attempting to save myself some typing by trying to concatenate two existing virtual generated columns into a new one that would display data from both.
In this example both the fullname and fulladdress columns are virtually generated and I tried to add them to a third virtual column named customer_information.
alter table customers add column customer_information varchar(300) generated always as (concat(fullname,' ', fulladdress)) after id;
I got the error, #4029 - Expression for field
customer_information
is referring to uninitialized fieldfullname
The solution that worked for me was to create a VIRTUAL GENERATED column that only referenced legitimate fields/columns in my table and not the virtual ones.
MariaDB does not allow a virtual generated column to depend on another virtual generated column because virtual columns are not physically stored and are computed on-the-fly. Secondly, when MariaDB tries to compute your customer_information
column, the values for fullname
and fulladdress
are not yet initialized, because they're also virtual.
Some workarounds you could consider are :
Use store generated columns instead
expand the expression fully