Invisible Columns
Explains how to define columns that are hidden from wildcard SELECT queries but remain accessible when explicitly referenced, facilitating schema changes without breaking existing applications.
Examples
CREATE TABLE t (x INT INVISIBLE);
ERROR 1113 (42000): A table must have at least 1 column
CREATE TABLE t (x INT, y INT INVISIBLE, z INT INVISIBLE NOT NULL);
ERROR 4106 (HY000): Invisible column `z` must have a default value
CREATE TABLE t (x INT, y INT INVISIBLE, z INT INVISIBLE NOT NULL DEFAULT 4);
INSERT INTO t VALUES (1),(2);
INSERT INTO t (x,y) VALUES (3,33);
SELECT * FROM t;
+------+
| x |
+------+
| 1 |
| 2 |
| 3 |
+------+
SELECT x,y,z FROM t;
+------+------+---+
| x | y | z |
+------+------+---+
| 1 | NULL | 4 |
| 2 | NULL | 4 |
| 3 | 33 | 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 | |
+-------+---------+------+-----+---------+-----------+Last updated
Was this helpful?

