Value Storage
Data Type Resolution for Value Storage
- Find an exact match with the target field.
- Attempt to directly convert the expression to the target type. If there is a registered conversion function between these two types, invoke the conversion function directly. If the expression is of an unknown text type, the contents of the text string will be passed to the input conversion process of the target type.
- Check if the target type has a length conversion. A length conversion is a transformation from a type to itself. If one is found in the pg_cast catalog, apply it to the expression before storing it into the target column. This kind of conversion function always takes an extra parameter of type integer, receiving the atttypmod value of the target column (essentially its declared length; the interpretation of atttypmod varies across different data types), and might also take a third parameter of type Boolean indicating whether the conversion is explicit or implicit. The conversion function is responsible for enforcing length-related semantics, such as length checks or truncations.
Examples
Conversion of the character storage type. For a statement where the target column is defined as character(20), the following demonstrates that the length of the stored value is accurate:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CREATE TABLE x1 ( customer_sk integer, customer_id char(20), first_name char(6), last_name char(8) ) store AS orc; INSERT INTO x1(customer_sk, customer_id, first_name) VALUES (3769, 'abcdef', 'Grace'); SELECT customer_id, octet_length(customer_id) FROM x1; customer_id | octet_length ----------------------+-------------- abcdef | 20 (1 row) DROP TABLE x1; |

Here is what truly occurs: Two unknown literals are by default resolved to text, enabling the || operator to resolve to text concatenation. Subsequently, the text result of the operation is transformed into bpchar (blank-padded character, the internal designation for the character type) to align with the target column type. Nonetheless, the transition from text to bpchar is binary-compatible, implying it is implicit and does not involve any actual function calls. Ultimately, the length conversion function bpchar(bpchar, integer, Boolean) is located within the system catalog and implemented upon both the operation's result and the stored column length. Functions associated with this type execute necessary length verifications along with supplementary blank padding.
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