Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
10.4. Value Storage
Prev UpChapter 10. Type ConversionHome Next

10.4. Value Storage#

Values to be inserted into a table are converted to the destination column's data type according to the following steps.

Value Storage Type Conversion

  1. Check for an exact match with the target.

  2. Otherwise, try to convert the expression to the target type. This is possible if anassignment cast between the two types is registered in thepg_cast catalog (seeCREATE CAST). Alternatively, if the expression is an unknown-type literal, the contents of the literal string will be fed to the input conversion routine for the target type.

  3. Check to see if there is a sizing cast for the target type. A sizing cast is a cast from that type to itself. If one is found in thepg_cast catalog, apply it to the expression before storing into the destination column. The implementation function for such a cast always takes an extra parameter of typeinteger, which receives the destination column'satttypmod value (typically its declared length, although the interpretation ofatttypmod varies for different data types), and it may take a thirdboolean parameter that says whether the cast is explicit or implicit. The cast function is responsible for applying any length-dependent semantics such as size checking or truncation.

Example 10.9. character Storage Type Conversion

For a target column declared ascharacter(20) the following statement shows that the stored value is sized correctly:

CREATE TABLE vv (v character(20));INSERT INTO vv SELECT 'abc' || 'def';SELECT v, octet_length(v) FROM vv;          v           | octet_length----------------------+-------------- abcdef               |           20(1 row)

What has really happened here is that the two unknown literals are resolved totext by default, allowing the|| operator to be resolved astext concatenation. Then thetext result of the operator is converted tobpchar (blank-padded char, the internal name of thecharacter data type) to match the target column type. (Since the conversion fromtext tobpchar is binary-coercible, this conversion does not insert any real function call.) Finally, the sizing functionbpchar(bpchar, integer, boolean) is found in the system catalog and applied to the operator's result and the stored column length. This type-specific function performs the required length check and addition of padding spaces.



Prev Up Next
10.3. Functions Home 10.5. UNION,CASE, and Related Constructs
pdfepub
Go to PostgreSQL 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp