From: | trainee12(at)yeah(dot)net |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: varchar and spaces problem.. |
Date: | 2003-01-17 02:39:35 |
Message-ID: | 3E276CE7.00006B.29612@bj216.163.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Don't store trail space char in VARCHAR column
You should recompile POSTGRESQl
There is tiny change in "src/backend/utils/atd/varchar.c"
**********************************************************
Datum
varcharin(PG_FUNCTION_ARGS)
{
char *s = PG_GETARG_CSTRING(0);
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
int32 atttypmod = PG_GETARG_INT32(2);
VarChar *result;
size_t len,
maxlen;
char *ermsg;
len = strlen(s);
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
maxlen = atttypmod - VARHDRSZ;
if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
{
/* Verify that extra characters are spaces, and clip them off */
size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen;
else
elog(ERROR, "value too long for type character varying(%d)",
(int) maxlen);
}
/* ******* truncate trail space char */
while (len > 0)
{
if (*(s + len - 1) != ' ')
break;
len--;
}
/* ******* */
result = palloc(len + VARHDRSZ);
VARATT_SIZEP(result) = len + VARHDRSZ;
memcpy(VARDATA(result), s, len);
#ifdef CYR_RECODE
convertstr(VARDATA(result), len, 0);
#endif
PG_RETURN_VARCHAR_P(result);
}
From | Date | Subject | |
---|---|---|---|
Next Message | Alberto Caso | 2003-01-17 02:57:25 | Re: Translation of the PostgreSQL manuals to |
Previous Message | trainee12 | 2003-01-17 02:31:22 | Re: varchar and spaces problem |