Skip to content

Commit

Permalink
REG_NOSUB is working only on PostgreSQL 15
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Apr 13, 2022
1 parent 12b4403 commit 8b96e44
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ orafce_replace_text_regexp(text *src_text, text *pattern_text,
/* Check whether replace_text has escapes, especially regexp submatches. */
escape_status = check_replace_text_has_escape(replace_text);

#if PG_VERSION_NUM >= 150000

/* REG_NOSUB doesn't work well in pre PostgreSQL 15 */

/* If no regexp submatches, we can use REG_NOSUB. */
if (escape_status < 2)
{
Expand All @@ -423,6 +427,8 @@ orafce_replace_text_regexp(text *src_text, text *pattern_text,
nmatch = 1;
}

#endif

/* Prepare the regexp. */
re = RE_compile_and_cache(pattern_text, cflags, collation);

Expand Down Expand Up @@ -629,7 +635,6 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
int orig_len;
pg_wchar *wide_str;
int wide_len;
int cflags;
regex_t *cpattern;
regmatch_t *pmatch;
int pmatch_len;
Expand All @@ -638,6 +643,7 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
int prev_match_end;
int prev_valid_match_end;
int maxlen = 0; /* largest fetch length in characters */
int cflags;

/* save original string --- we'll extract result substrings from it */
matchctx->orig_str = orig_str;
Expand All @@ -649,8 +655,16 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,

/* set up the compiled pattern */
cflags = re_flags->cflags;

#if PG_VERSION_NUM >= 150000

/* REG_NOSUB doesn't work well in pre PostgreSQL 15 */

if (!use_subpatterns)
cflags |= REG_NOSUB;

#endif

cpattern = RE_compile_and_cache(pattern, cflags, collation);

/* do we want to remember subpatterns? */
Expand Down

0 comments on commit 8b96e44

Please sign in to comment.