Given the following example table, I would like the default value of str_field_hash
to contain the SHA1 hash of the value of str_field
.
CREATE TABLE test (
str_field VARCHAR(1024) NOT NULL,
str_field_hash CHAR(40) NOT NULL,
CONSTRAINT str_field_hash_unique UNIQUE (str_field_hash)
);
str_field
is too large for a unique key constraint.
This question contains answers indicating the newer versions of MySQL/MariaDB support using functions in default column values, though I've been unable to find information on whether I can derive a default value for a column from the value provided for another column.
I know I can use a trigger for this, but I'd love to keep it all confined to the table schema itself if possible.
Developing using MySQL v8.0.11.