From b7f83e70d9758c5dd480c9dbba1668ddeec37916 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 6 Sep 2011 12:14:51 -0400 Subject: [PATCH] Update type-conversion documentation for long-ago changes. This example wasn't updated when we changed the behavior of bpcharlen() in 8.0, nor when we changed the number of parameters taken by the bpchar() cast function in 7.3. Per report from lsliang. --- doc/src/sgml/typeconv.sgml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/typeconv.sgml b/doc/src/sgml/typeconv.sgml index f233e9d712..cca45eb569 100644 --- a/doc/src/sgml/typeconv.sgml +++ b/doc/src/sgml/typeconv.sgml @@ -758,9 +758,11 @@ cast is a cast from that type to itself. If one is found in the pg_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 type integer, which receives -the destination column's declared length (actually, its -atttypmod value; the interpretation of -atttypmod varies for different data types). The cast function +the destination column's atttypmod value (typically its +declared length, although the interpretation of atttypmod +varies for different data types), and it may take a third boolean +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. @@ -772,17 +774,17 @@ checking or truncation. <type>character</type> Storage Type Conversion -For a target column declared as character(20) the following statement -ensures that the stored value is sized correctly: +For a target column declared as character(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, length(v) FROM vv; +SELECT v, octet_length(v) FROM vv; - v | length -----------------------+-------- - abcdef | 20 + v | octet_length +----------------------+-------------- + abcdef | 20 (1 row) @@ -796,7 +798,7 @@ char, the internal name of the character data type) to match the column type. (Since the conversion from text to bpchar is binary-coercible, this conversion does not insert any real function call.) Finally, the sizing function -bpchar(bpchar, integer) is found in the system catalog +bpchar(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. -- GitLab