Re: Counting the occurences of a substring within a very large text

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: "'Albe Laurenz'" <laurenz(dot)albe(at)wien(dot)gv(dot)at>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Counting the occurences of a substring within a very large text
Date: 2015-06-24 13:28:14
Message-ID: B6F6FD62F2624C4C9916AC0175D56D8828BEA709@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Albe Laurenz [mailto:laurenz(dot)albe(at)wien(dot)gv(dot)at]
> Sent: Mittwoch, 24. Juni 2015 13:44
> To: Marc Mamin; Postgres General
> Subject: RE: Counting the occurences of a substring within a very large
> text
>
> Marc Mamin wrote:
> > I'd like to count the number linebreaks within a string, but I get a
> > memory allocation error when using regexp_matches or
> regexp_split_to_table.
> >
> > Any idea for an alternative to this problem ?
> >
> > select count(*)-1 from
> > ( select regexp_split_to_table(full_message,'(\n)', 'g')
> > from mytable
> > where id =-2146999703
> > )foo;
> >
> > ERROR: invalid memory alloc request size 1447215584
>
> Does any of these two work:
>
> SELECT length(regexp_replace(full_message, '[^\n]', '', 'g')) FROM
> mytable WHERE id = -2146999703;
>
> or
>
> SELECT length(full_message) - length(replace(full_message, E'\n', ''))
> FROM mytable WHERE id = -2146999703;

no, they both yeld the same error.

a new string functions for this would be nice, as it could certainly be implemented in a more efficient way...

BTW: the text to check is a single 350 MB error message from a log file :)

>
> Yours,
> Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc Mamin 2015-06-24 13:30:07 Re: Counting the occurences of a substring within a very large text
Previous Message Andy Colson 2015-06-24 13:24:45 Re: Counting the occurences of a substring within a very large text