Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

character type value is not padded with spaces


  • From: Yoshiyuki Asaba <y-asaba(at)sra(dot)co(dot)jp>
  • To: pgsql-patches(at)postgresql(dot)org
  • Subject: character type value is not padded with spaces
  • Date: Mon, 23 May 2005 11:05:26 +0900 (JST)
  • Message-id: <20050523.110526.93017548.y-asaba@sra.co.jp> <text/plain>

Character type value including multibyte characters is not padded
with spaces. It reproduces at 7.3.x, 7.4.x and 8.0.x.

   create table t (a char(10));
   insert into t values ('XXXXX'); -- X is 2byte character.

I expect that 'XXXXX     ' is inserted. But 'XXXXX' is inserted.

   select a, octed_length(a) from t;

      a   | octet_length 
   -------+--------------
    XXXXX |           10

If padded with spaces, octet_length(a) is 15. This problem is caused
that string length is calculated by byte length(VARSIZE) in
exprTypmod().

I attache the patch for this problem.

Regards,

--
Yoshiyuki Asaba
y-asaba(at)sra(dot)co(dot)jp
*** parse_expr.c.orig	2005-01-13 02:32:36.000000000 +0900
--- parse_expr.c	2005-05-22 17:12:37.000000000 +0900
***************
*** 18,23 ****
--- 18,24 ----
  #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,40 ****
  #include "utils/lsyscache.h"
  #include "utils/syscache.h"
  
- 
  bool		Transform_null_equals = false;
  
  static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
--- 35,40 ----
***************
*** 1491,1497 ****
  				{
  					case BPCHAROID:
  						if (!con->constisnull)
! 							return VARSIZE(DatumGetPointer(con->constvalue));
  						break;
  					default:
  						break;
--- 1491,1503 ----
  				{
  					case BPCHAROID:
  						if (!con->constisnull)
! 						{
! 							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;


Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group