Re: Counting the occurences of a substring within a very large text - Mailing list pgsql-general

From Albe Laurenz
Subject Re: Counting the occurences of a substring within a very large text
Date
Msg-id A737B7A37273E048B164557ADEF4A58B50F6824C@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Counting the occurences of a substring within a very large text  (Marc Mamin <M.Mamin@intershop.de>)
Responses Re: Counting the occurences of a substring within a very large text  (Marc Mamin <M.Mamin@intershop.de>)
List pgsql-general
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;

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: Chris Mair
Date:
Subject: Re: Counting the occurences of a substring within a very large text
Next
From: Andy Colson
Date:
Subject: Re: Counting the occurences of a substring within a very large text