Comments - Dynamic Columns
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
Using the table:
CREATE TABLE `person` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fname` varchar(255) NOT NULL, `lname` varchar(255) NOT NULL, `car_make` varchar(255) DEFAULT NULL, `car_model` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) engine=MYISAM;
This works:
SELECT COLUMN_JSON(COLUMN_CREATE('first_name', fname, 'last_name', lname, 'car', COLUMN_CREATE('make', car_make, 'model', car_model))) AS person_data FROM person WHERE id = 57;
But this returns junks:
SELECT COLUMN_CREATE('first_name', fname, 'last_name', lname) AS person_data, COLUMN_CREATE('make', car_make, 'model', car_model) AS car_data FROM person WHERE id = 57;
Why? Or what's wrong in it?
COLUMN_CREATE() returns a dynamic column blob, which is suitable for storing in a table, or for use with another function as you did in your first example, but not for SELECTing on its own.