Question

How can I programmatically list all available datatypes in MySQL?

Like SELECT * FROM sys.types in MS-SQL.

I believe it is not possible, but anybody knows for sure ?

Note: I do not need only the types used as in

SELECT DISTINCT data_type FROM information_schema.columns
Was it helpful?

Solution

It is not possible to programmatically list data types available in MySQL, unfortunately. MySQL doesn't have user-defined types, so it's less of a problem to hard-code a type list, as it doesn't change much (yet). Presumably when UDTs would be implemented, someone would also add an information_schema.types table. If you want to see all types currently implemented, you can check the source code sql/sql_yacc.yy e.g. for MySQL 5.6.15 here:

https://github.com/darnaut/mysql-server/blob/mysql-5.6.15/sql/sql_yacc.yy#L6399

(This assumes you can read yacc and C++ syntax.)

OTHER TIPS

I have the same need. Here's what i did:

  1. Create a table with all field type available
CREATE TABLE dlweb_doc_test.TEST_DATA_TYPE ( Field1 TINYINT, Field2 SMALLINT, Field3 INT, Field4 MEDIUMINT, Field5 BIGINT, Field6 REAL, Field7 DOUBLE, Field8 FLOAT, Field9 DECIMAL, Field10 NUMERIC, Field11 DATE, Field12 YEAR, Field13 TIME, Field14 TIMESTAMP, Field15 DATETIME, Field16 BIT, Field17 VARCHAR(20), Field18 CHAR ASCII, Field19 BINARY(3), Field20 VARBINARY(2),   Field21 TINYTEXT ASCII, Field22 TEXT ASCII, Field23 MEDIUMTEXT ASCII, Field24 LONGTEXT ASCII, Field25 ENUM('1'), Field26 SET('1'), Field27 GEOMETRY, Field28 POINT, Field29 LINESTRING, Field30 POLYGON, Field31 MULTIPOINT, Field32 MULTILINESTRING, Field33 MULTIPOLYGON, Field34 GEOMETRYCOLLECTION ) ENGINE = InnoDB ROW_FORMAT = DEFAULT;
  1. Use the query SELECT DISTINCT data_type FROM information_schema.columns

  2. Here's the list of DATA_TYPE values:

bigint
double
longtext
datetime
int
decimal
tinyint
text
longblob
mediumblob
blob
date
smallint
mediumint
float
year
time
timestamp
bit
char
binary
varbinary
tinytext
mediumtext
enum
set
geometry
point
linestring
polygon
multipoint
multilinestring
multipolygon
geometrycollection```
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top