pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15595: matchctx->npatterns is always 1 no matter pattern have 0 or 1 subexpression
3+ messages / 3 participants
[nested] [flat]

* BUG #15595: matchctx->npatterns is always 1 no matter pattern have 0 or 1 subexpression
@ 2019-01-17 01:30  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 2 replies; 3+ messages in thread

From: PG Bug reporting form @ 2019-01-17 01:30 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: zhq651@126.com

The following bug has been logged on the website:

Bug reference:      15595
Logged by:          Damion
Email address:      zhq651@126.com
PostgreSQL version: 11.1
Operating system:   linux
Description:        

Hi,
when I use setup_regexp_matches, I found matchctx->npatterns is always 1 no
matter pattern  have not or one subexpr subexpression.
so I can't tell whether there is a subexpression. see below:

 if orig_str is '221133' & pattern  is  '11'
(gdb) p nth_subexpr
$23 = 1
(gdb) p matchctx->npatterns
$24 = 1

 if orig_str is '221133' & pattern  is  '(11)'
(gdb) p nth_subexpr
$25 = 1
(gdb) p matchctx->npatterns
$26 = 1

if pattern  is  '((1)1)' or '((11))' (2 subexpression  or more), I can kwown
how many subexpression by matchctx->npatterns .
postgres=# SELECT regexp_substr('221133', '((1)1)', 1, 1, 'i', 1);
(gdb) p matchctx->npatterns
$27 = 2
(gdb) p nth_subexpr
$28 = 1

Thanks.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15595: matchctx->npatterns is always 1 no matter pattern have 0 or 1 subexpression
@ 2019-01-17 02:28  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2019-01-17 02:28 UTC (permalink / raw)
  To: zhq651@126.com; +Cc: pgsql-bugs@lists.postgresql.org

=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> when I use setup_regexp_matches, I found matchctx->npatterns is always 1 no
> matter pattern  have not or one subexpr subexpression.

It seems unlikely that this is a Postgres bug.

Just looking at the code in setup_regexp_matches, I wonder whether you
are passing use_subpatterns = true or not:

    /* do we want to remember subpatterns? */
    if (use_subpatterns && cpattern->re_nsub > 0)
    {
        matchctx->npatterns = cpattern->re_nsub;
        pmatch_len = cpattern->re_nsub + 1;
    }
    else
    {
        use_subpatterns = false;
        matchctx->npatterns = 1;
        pmatch_len = 1;
    }

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15595: matchctx->npatterns is always 1 no matter pattern have 0 or 1 subexpression
@ 2019-01-17 02:31  Andrew Gierth <andrew@tao11.riddles.org.uk>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Andrew Gierth @ 2019-01-17 02:31 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; zhq651@126.com

>>>>> "PG" == PG Bug reporting form <noreply@postgresql.org> writes:

 PG> Hi,
 PG> when I use setup_regexp_matches, I found matchctx->npatterns is
 PG> always 1 no matter pattern have not or one subexpr subexpression.

This isn't a bug. setup_regexp_matches is just an internal helper
function for use by regexp_match, regexp_matches, regexp_split_to_table,
and regexp_split_to_array, all of which treat the whole match as the
result if there are no subexpression captures in the regexp. npatterns
is therefore forced to be 1 in that case, so that nmatches * npatterns
is the number of position pairs returned in the match_locs array.

-- 
Andrew (irc:RhodiumToad)




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-01-17 02:31 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 01:30 BUG #15595: matchctx->npatterns is always 1 no matter pattern have 0 or 1 subexpression PG Bug reporting form <noreply@postgresql.org>
2019-01-17 02:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-01-17 02:31 ` Andrew Gierth <andrew@tao11.riddles.org.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox