String Types
Overview
MySQL interprets length specifications in character column definitions in character units. This applies to the CHAR, VARCHAR, and TEXT types. DSC supports the following type conversions:
Type Mapping
MySQL String Type |
MySQL INPUT |
GaussDB(DWS) OUTPUT |
---|---|---|
CHAR |
CHAR[(0)] CHAR[(n)] |
CHAR[(1)] CHAR[(4n)] |
CHARACTER |
CHARACTER[(0)] CHARACTER[(n)] |
CHAR[(1)] CHAR[(4n)] |
NCHAR |
NCHAR[(0)] NCHAR[(n)] |
CHAR[(1)] CHAR[(4n)] |
LONGTEXT |
LONGTEXT |
TEXT |
MEDIUMTEXT |
MEDIUMTEXT |
TEXT |
TEXT |
TEXT |
TEXT |
TINYTEXT |
TINYTEXT |
TEXT |
VARCHAR |
VARCHAR[(0)] VARCHAR[(n)] |
VARCHAR[(1)] VARCHAR[(4n)] |
NVARCHAR |
NVARCHAR[(0)] NVARCHAR[(n)] |
VARCHAR[(1)] VARCHAR[(4n)] |
CHARACTE VARYING |
CHARACTE VARYING |
VARCHAR |
- During CHAR/CHARACTER/NCHAR conversion, if the precision is less than or equal to 0, it is converted to CHAR(1). If the precision is greater than 0, it is converted to a precision level four times that of the CHAR type.
- During VARCHAR/NVARCHAR conversion, if the precision is less than or equal to 0, it is converted to VARCHAR(1). If the precision is greater than 0, it is converted to a precision four times that of the VARCHAR type.
Input: CHAR
In MySQL, the size of a CHAR column is set to a fixed length specified at table creation, ranging from 0 to 255. Stored CHAR values are right-padded with spaces to meet this specified length.
1 2 3 4 5 |
CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` CHAR NOT NULL, `dataType_2` CHAR(0) NOT NULL, `dataType_3` CHAR(255) NOT NULL ); |
Output
1 2 3 4 5 6 7 8 9 |
CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" CHAR NOT NULL, "datatype_2" CHAR(1) NOT NULL, "datatype_3" CHAR(1020) NOT NULL ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); |
Input: [LONG|MEDIUM|TINY]TEXT
1 2 3 4 5 6 |
CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` LONGTEXT, `dataType_2` MEDIUMTEXT, `dataType_3` TEXT, `dataType_4` TINYTEXT ); |
Output
1 2 3 4 5 6 7 8 9 10 |
CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" TEXT, "datatype_2" TEXT, "datatype_3" TEXT, "datatype_4" TEXT ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); |
Input: VARCHAR
In MySQL, values in VARCHAR columns are variable-length strings. The length can be any value from 0 to 65,535.
1 2 3 4 |
CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` VARCHAR(0), `dataType_2` VARCHAR(1845) ); |
Output
1 2 3 4 5 6 7 8 |
CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" VARCHAR(1), "datatype_2" VARCHAR(7380) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot