Skip to content

Commit a90e9d6

Browse files
committed
Inserting 5 characters into char(10) does not produce 5 padding spaces
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.
1 parent 11a0c37 commit a90e9d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/parser/parse_expr.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.181 2005/04/06 16:34:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.182 2005/05/24 15:45:34 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -18,6 +18,7 @@
1818
#include "catalog/pg_operator.h"
1919
#include "catalog/pg_proc.h"
2020
#include "commands/dbcommands.h"
21+
#include "mb/pg_wchar.h"
2122
#include "miscadmin.h"
2223
#include "nodes/makefuncs.h"
2324
#include "nodes/params.h"
@@ -34,7 +35,6 @@
3435
#include "utils/lsyscache.h"
3536
#include "utils/syscache.h"
3637

37-
3838
bool Transform_null_equals = false;
3939

4040
static Node *transformParamRef(ParseState *pstate, ParamRef *pref);
@@ -1553,7 +1553,13 @@ exprTypmod(Node *expr)
15531553
{
15541554
case BPCHAROID:
15551555
if (!con->constisnull)
1556-
return VARSIZE(DatumGetPointer(con->constvalue));
1556+
{
1557+
int32 len = VARSIZE(DatumGetPointer(con->constvalue)) - VARHDRSZ;
1558+
1559+
if (pg_database_encoding_max_length() > 1)
1560+
len = pg_mbstrlen_with_len(VARDATA(DatumGetPointer(con->constvalue)), len);
1561+
return len + VARHDRSZ;
1562+
}
15571563
break;
15581564
default:
15591565
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy