diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index fc3c5b0..fdf58cf 100644 *** a/src/backend/utils/adt/selfuncs.c --- b/src/backend/utils/adt/selfuncs.c *************** make_greater_string(const Const *str_con *** 5542,5552 **** *lastchar = savelastchar; /* ! * Truncate off the last character, which might be more than 1 byte, ! * depending on the character encoding. */ if (datatype != BYTEAOID && pg_database_encoding_max_length() > 1) ! len = pg_mbcliplen(workstr, len, len - 1); else len -= 1; --- 5542,5567 ---- *lastchar = savelastchar; /* ! * Increment the previous character, or truncate off the last character, ! * which might be more than 1 byte, depending on the character encoding. */ if (datatype != BYTEAOID && pg_database_encoding_max_length() > 1) ! { ! int i; ! int cliplen = pg_mbcliplen(workstr, len, len - 1); ! ! for (i = len - 1; i > cliplen; i--) ! { ! if ((unsigned char) workstr[i] < (unsigned char) 255) ! { ! workstr[i]++; ! memset(workstr + i + 1, 1 /* or 0? */, len - i); ! break; ! } ! } ! if (i <= cliplen) ! len = cliplen; ! } else len -= 1;