Column data type

2019-09-01 06:17发布

问题:

I have an application that has to load various H2 database files for different tasks at runtime and must be able to verify that the loaded DB conforms to a predefined schema. By this I mean that I query the information schema to check whether specific tables are present and whether these tables contain properly defined columns (eg data type, length, indexes etc).

My question is concerning H2's internal data types and how they map to values listed in INFORMATION_SCHEMA.COLUMNS. For example am I correct that the data_type column in this table properly reflects a columns data type as given during table creation eg

CREATE TABLE test (id int primary key, some_string varchar(32) ... )

the int is mapped to a data type of 4? Is there a listing of the mappings of the data types to internal codes and do these ever change?

回答1:

The column DATA_TYPE in the table table INFORMATION_SCHEMA.COLUMNS is mapped to column 5 (DATA_TYPE) of the method DatabaseMetaData.getColumns. Per specification this is required to be an integer, as defined in java.sql.Types. The constant 4 means INTEGER.

This is part of the JDBC standard and is not going to change.



标签: types schema h2