Inserting 5 characters into char(10) does not produce 5 padding spaces
authorTatsuo Ishii <[email protected]>
Tue, 24 May 2005 23:52:02 +0000 (23:52 +0000)
committerTatsuo Ishii <[email protected]>
Tue, 24 May 2005 23:52:02 +0000 (23:52 +0000)
if they are two-byte multibyte characters. Same thing can be happen
if octet_length(multibyte_chars) == n where n is char(n).
Long standing bug since 7.3 days. Per report and fix from Yoshiyuki Asaba.

src/backend/parser/parse_expr.c

index 646c8ae39d1689d08d50557ff6f8bceb5f938bb9..1aaf1cf3943159ea98b7f809d7c53c30d07d1f6b 100644 (file)
@@ -18,6 +18,7 @@
 #include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "commands/dbcommands.h"
+#include "mb/pg_wchar.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/params.h"
@@ -34,7 +35,6 @@
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
 
-
 bool           Transform_null_equals = false;
 
 static Node *transformParamRef(ParseState *pstate, ParamRef *pref);
@@ -1553,7 +1553,13 @@ exprTypmod(Node *expr)
                                {
                                        case BPCHAROID:
                                                if (!con->constisnull)
-                                                       return VARSIZE(DatumGetPointer(con->constvalue));
+                                               {
+                                                       int32 len = VARSIZE(DatumGetPointer(con->constvalue)) - VARHDRSZ;
+
+                                                       if (pg_database_encoding_max_length() > 1)
+                                                               len = pg_mbstrlen_with_len(VARDATA(DatumGetPointer(con->constvalue)), len);
+                                                       return len + VARHDRSZ;
+                                               }
                                                break;
                                        default:
                                                break;