Re: Regular expression and Group By

From: Clodoaldo <clodoaldo(dot)pinto(dot)neto(at)gmail(dot)com>
To: "Jeff Davis" <pgsql(at)j-davis(dot)com>
Cc: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Regular expression and Group By
Date: 2006-12-19 13:37:49
Message-ID: a595de7a0612190537r613b8f35pc4a35c8d3a40fd9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2006/12/18, Jeff Davis <pgsql(at)j-davis(dot)com>:
> On Fri, 2006-12-15 at 17:21 -0200, Clodoaldo wrote:
> > -- drop table test_table;
> > create table test_table (tname varchar, value integer);
> > insert into test_table values ('[ab]x', 1);
> > insert into test_table values ('[ab]y', 2);
> > insert into test_table values ('[Ab]z', 3);
> > insert into test_table values ('w[aB]', 8);
> > insert into test_table values ('[abx', 4);
> > insert into test_table values ('ab]x', 5);
> > insert into test_table values ('xyz', 6);
> > insert into test_table values ('Xyz', 7);
> >
> ...
> > total | tname | value_total
> > -------+-------+-------------
> > 4 | [AB] | 14
> > 1 | [abx | 4
> > 1 | ab]x | 5
> > 1 | xyz | 6
> > 1 | Xyz | 7
> > (5 rows)
> >
>
> It looks like what you need is a function that returns the upper() of
> the substring enclosed by "[]" if that substring exists, or else the
> original string.
>
> In other words, make a user-defined function that turns the string into
> "tname" and GROUP BY the result of that function.
>

That worked. I was fixed in solving it with a regular expression and
didn't see the obvious.

Thanks.
--
Clodoaldo Pinto Neto

In response to

Browse pgsql-general by date

  From Date Subject
Next Message michael.guiard 2006-12-19 13:47:27 Re: strange slow performance
Previous Message Magnus Hagander 2006-12-19 13:16:13 Re: Let's play bash the search engine