Character Types
Table 1 lists the character types supported by M-compatible databases.
|
Name |
Description |
Storage Space |
|---|---|---|
|
CHAR[(n)] |
Fixed-length character string. Empty characters are filled in with blank spaces. n indicates the string length. If it is not specified, the default precision 1 is used. |
Up to 255 characters |
|
VARCHAR(n) |
Variable-length character string. n indicates the string length. |
Up to 65532 bytes |
|
TEXT[(n)] |
Variable-length character string. n indicates the optional string length of the type. After n is specified, a column is created as the TEXT type that has the minimum length but is sufficient to hold the byte length corresponding to n characters. |
Up to 65535 bytes |
|
TINYTEXT |
Variable-length character string. |
Up to 255 bytes |
|
MEDIUMTEXT |
Variable-length character string. |
Up to 16777215 bytes |
|
LONGTEXT |
Variable-length character string. |
Up to 1 GB minus 1 byte |
- If the value of sql_mode contains strict_trans_tables and the input value is invalid or exceeds the storage space range, an error is reported.
- If the value of sql_mode does not contain strict_trans_tables and the input value is invalid or exceeds the storage space range, a warning message is reported and the truncated value is returned.
- If the value of sql_mode contains pad_char_to_full_length and table columns and temporary variables are of the CHAR type, the character string with trailing spaces is output. If the value of sql_mode does not contain pad_char_to_full_length and table columns and temporary variables are of the CHAR type, the character string with no trailing spaces is output.
- The '||' connector is not supported.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
-- Create a table. m_db=# CREATE TABLE text_type_t1 ( BT_COL1 CHAR(10), BT_COL2 VARCHAR(10), BT_COL3 TEXT, BT_COL4 TEXT(10) ); -- Insert data. m_db=# INSERT INTO text_type_t1 VALUES ('text_test1', 'text_test2','text_test3','text_test4'); -- Query data in the table. m_db=# SELECT * FROM text_type_t1; bt_col1 | bt_col2 | bt_col3 | bt_col4 ------------+------------+------------+------------ text_test1 | text_test2 | text_test3 | text_test4 (1 row) -- Drop the table. m_db=# DROP TABLE text_type_t1; -- Example: CHAR type. -- Create a table. m_db=# CREATE TABLE char_type_t2 ( BT_COL1 CHAR(5) ); -- With the strict mode enabled, an error is reported if the length of an inserted string exceeds the length specified for the type. m_db=# SET SQL_MODE = 'strict_trans_tables,only_full_group_by,no_zero_in_date,no_zero_date,error_for_division_by_zero, no_auto_create_user,no_engine_substitution'; SET m_db=# INSERT INTO char_type_t2 VALUES ('too long'); ERROR: value too long for type character(5) CONTEXT: referenced column: BT_COL1 -- With the strict mode disabled, a warning message is reported and the value is truncated if the length of an inserted string exceeds the length specified for the type. m_db=# SET SQL_MODE = ''; SET m_db=# INSERT INTO char_type_t2 VALUES ('too long'); WARNING: value too long for type character(5) CONTEXT: referenced column: BT_COL1 INSERT 0 1 -- Query data in the table. m_db=# SELECT * FROM char_type_t2 ; bt_col1 --------- too l (1 row) -- Drop the table. m_db=# DROP TABLE blob_type_t2; |
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