From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | Tarlika Elisabeth Schmitz <postgresql(at)numerixtechnology(dot)de> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: extracting words |
Date: | 2008-04-23 13:13:03 |
Message-ID: | 20080423131303.GE4768@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tarlika Elisabeth Schmitz wrote:
> I need to extract the words from department_name and product_name
> (words are separated by spaces) and get something like:
>
> 1 cakes
> 1 desserts
> 1 apple
> 1 crumble
> 2 cakes
> 2 desserts
> 2 cheese
> 2 cake
> 3 starters
> 3 soups
> 3 french
> 3 onion
> 3 soup
regexp_split_to_table is handy (8.3 only):
select pk, regexp_split_to_table(product_name, '[& ]+') from products
union
select pk, regexp_split_to_table(dept_name, '[& ]+') from departments;
Add joins as desired.
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
From | Date | Subject | |
---|---|---|---|
Next Message | Tarlika Elisabeth Schmitz | 2008-04-23 14:57:35 | Re: extracting words |
Previous Message | A. Kretschmer | 2008-04-23 05:18:44 | Re: extracting words |