Values to be inserted into a table are coerced to the destination
column's data type according to the
following steps.
Example 7-6. character Storage Type Conversion
For a target column declared as character(20) the following query
ensures that the target is sized correctly:
tgl=> CREATE TABLE vv (v character(20));
CREATE
tgl=> INSERT INTO vv SELECT 'abc' || 'def';
INSERT 392905 1
tgl=> SELECT v, length(v) FROM vv;
v | length
----------------------+--------
abcdef | 20
(1 row)
What has really happened here is that the two unknown literals are resolved
to text by default, allowing the || operator
to be resolved as text concatenation. Then the text
result of the operator is coerced to bpchar ("blank-padded
char", the internal name of the character data type) to match the target
column type. (Since the parser knows that text and
bpchar are binary-compatible, this coercion is implicit and does
not insert any real function call.) Finally, the sizing function
bpchar(bpchar, integer) is found in the system catalogs
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.