Mariadb – How to use MariaDB’s new “Invisible” column type

mariadb-10.3

I have been playing around with this new column type. The use case being that I want to hide this column from a client issuing a "Select *" query.

But the column seems to behave like any normal column and is not hidden. I have enabled the Invisible column type by using the following command:

ALTER TABLE MyTable ADD COLUMN `TestA` INT INVISIBLE;

Reading up in the MariaDB documentation, the examples provided are only with Create statements. Which makes me wonder if one can only enable this feature when creating a table and NOT with an Alter statement. Can anybody shed some light?

Best Answer

The INVISIBLE is an attribute of the column it can be set CREATE TABLE and ALTER TABLE statements.

I've updated the reference page document to show this.

 CREATE TABLE t (x INT, y INT INVISIBLE, z INT INVISIBLE NOT NULL DEFAULT 4);

 DESC t;
Field | Type    | Null | Key | Default | Extra    
:---- | :------ | :--- | :-- | :------ | :--------
x     | int(11) | YES  |     | null    |          
y     | int(11) | YES  |     | null    | INVISIBLE
z     | int(11) | NO   |     | 4       | INVISIBLE
ALTER TABLE t MODIFY x INT INVISIBLE, MODIFY y INT, MODIFY z INT NOT NULL DEFAULT 4

DESC t
Field | Type    | Null | Key | Default | Extra    
:---- | :------ | :--- | :-- | :------ | :--------
x     | int(11) | YES  |     | null    | INVISIBLE
y     | int(11) | YES  |     | null    |          
z     | int(11) | NO   |     | 4       |          

db<>fiddle here