*** ./src/backend/utils/adt/regexp.c.orig Sun Mar 5 21:28:43 2006 --- ./src/backend/utils/adt/regexp.c Wed Apr 19 12:23:30 2006 *************** *** 522,527 **** --- 522,529 ---- elen; bool afterescape = false; int nquotes = 0; + int index; + bool paranFlag = false; /* This function is not strict, so must test explicitly */ if (PG_ARGISNULL(0)) *************** *** 549,559 **** errhint("Escape string must be empty or one character."))); } /* We need room for ^, $, and up to 2 output bytes per input byte */ ! result = (text *) palloc(VARHDRSZ + 2 + 2 * plen); r = VARDATA(result); *r++ = '^'; while (plen > 0) { --- 551,583 ---- errhint("Escape string must be empty or one character."))); } + /* Add parenthesis */ + for(index = 0; index < plen; index++) + { + char pchar = *(p+index); + + if (pchar == '"' || pchar == '%' || pchar == '_' || pchar == '\\' || + pchar == '.' || pchar == '?' || pchar == '{' || pchar == '(' || pchar == ')') + { + paranFlag = false; + break; + } + else if (pchar == '|') + paranFlag = true; + + } + /* We need room for ^, $, and up to 2 output bytes per input byte */ ! if (paranFlag == true) ! result = (text *) palloc(VARHDRSZ + 2 + 2 + 2 * plen); ! else ! result = (text *) palloc(VARHDRSZ + 2 + 2 * plen); ! r = VARDATA(result); *r++ = '^'; + if (paranFlag == true) + *r++ = '('; while (plen > 0) { *************** *** 593,598 **** --- 617,625 ---- p++, plen--; } + if (paranFlag == true) + *r++ = ')'; + *r++ = '$'; VARATT_SIZEP(result) = r - ((char *) result);