Type Conversion Value Storage in OushuDB User Guide

The values ​​to be inserted into the table are also converted to the data type of the target column according to the following steps.

Value storage data type resolution

1. Find an exact match to the target.

2. Otherwise, try converting the expression directly to the target type. If it is known that there is a registered conversion function between these two types, then the conversion function can be called directly. If the expression is a text of an unknown type, the contents of the text string are passed to the input conversion process of the target type.

  1. Check to see if the target type has a length conversion. A length conversion is a conversion from a type to itself. If one is found in the pg_cast table, it is applied on the expression before storing into the target column. Such a conversion function always accepts an additional argument of type integer, which accepts the atttypmod value of the target field (actually its declared length, the interpretation of atttypmod varies with different data types), and it may accept a boolean type The third parameter of , indicating whether the conversion is explicit or implicit. Conversion functions are responsible for imposing those length-related semantics, such as length checking or truncation.

Example. character storage type conversion

For a statement with a target column defined as character(20), the following statement shows that the stored value is of the correct length:

CREATETABLEvv (vcharacter(20));INSERTINTOvvSELECT'abc'||'def';SELECTv, octet_length(v) FROMvv;v|octet_length----------------------+--------------abcdef|20(1row)

What's really happening here is that two unknown literals resolve to text by default, which allows the || operator to resolve to a text concatenation. The text result of the operator is then converted to bpchar ("blank padded character type", the internal name of the character type) to match the target column type. (Because the conversion from text to bpchar is binary compatible, such conversion is implicit and does not actually make any function calls.) Finally, find the length conversion function bpchar(bpchar, integer, boolean) in the system table and apply depends on the result of this operator and the length of the stored field. This type-dependent function performs the required length checking and additional whitespace padding.

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324123843&siteId=291194637