Implicit Type Conversion
Implicit type conversion mainly applies to function calls, operators, and value storage scenarios. This section describes type resolution in the value storage scenario. For details about other scenarios, see Functions and Operators.
Value Storage Type Resolution
- Search for an exact match with the target column.
- Try to convert the expression to the target type. If a registered cast function exists between the two types, call the cast function directly. If the expression is an unknown-type literal, the content of the literal string will be passed to the input conversion routine for the target type.
- Check whether there is a sizing cast for the target type. A sizing cast is a cast from that type to itself. If the target type has sizing cast logic, convert it to the expression before storing into the destination column. The cast function receives a parameter of the INTEGER type and the value of atttypmod of the target field (the value is the length specified by the function, and the meaning of atttypmod varies according to the data types). In addition, the function may receive a Boolean data record as the third parameter, indicates the conversion mode (explicit conversion or implicit conversion). The cast function is responsible for setting length-dependent statements such as sizing check or truncation.
Example:
1 2 3 4 5 6 7 8 9 10 11 |
m_db=# CREATE TABLE char_storage ( VS_COL1 CHAR(20) ); m_db=# INSERT INTO char_storage VALUES('abcdef'); m_db=# SELECT VS_COL1, length(VS_COL1) FROM char_storage; VS_COL1 | length ---------+-------- abcdef | 6 (1 row) m_db=# DROP TABLE char_storage; |
Convert the FLOAT storage type to the BINARY storage type. Insert the value obtained from the FLOAT column to the table whose target column is BINARY(5).
1 2 3 4 5 6 7 8 9 |
m_db=# CREATE TABLE varchar_storage ( VS_COL1 BINARY(5) ) DISTRIBUTE BY REPLICATION; m_db=# CREATE TABLE float_storage ( VS_COL1 FLOAT ) DISTRIBUTE BY REPLICATION; m_db=# INSERT INTO float_storage VALUES(1234567); m_db=# INSERT INTO varchar_storage SELECT * FROM float_storage; m_db=# DROP TABLE varchar_storage, float_storage; |
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