Re: How to get normalized data from tekst column

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to get normalized data from tekst column
Date: 2011-11-24 16:21:05
Message-ID: 86ipm9ebke.fsf@protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Andrus" <kobruleht2(at)hot(dot)ee> writes:

> David,
>>Regular Expressions are your friend here. If you do not know them you
> should learn them; though if you ask nicely someone may just provide you
> the solution you need.
>>Split-to-array and unnest may work as well.
>
> Thank you very much. I dona**t know regexps.
> Can you provide example, please for 8.1. Or maybe CASE WHEN and substring
> testing can also used.

The query

SELECT id, a[1] AS name, a[2] AS percent
FROM (
SELECT id, regexp_split_to_array(regexp_split_to_table(comment, ', *'), '\W+') AS a
FROM project
) AS dummy

should work un every halfway recent PostgreSQL version - dunno about 8.1.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-11-24 17:13:29 Re: "CREATE TABLE table_name AS EXECUTE name WITH DATA" becomes syntax error.
Previous Message Phoenix Kiula 2011-11-24 16:20:44 Re: Incremental backup with RSYNC or something?