Re: [SQL] extracting words

2008-04-23 Thread Alvaro Herrera
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 Herrerahttp://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] extracting words

2008-04-23 Thread Tarlika Elisabeth Schmitz
On Wed, 23 Apr 2008 09:13:03 -0400
Alvaro Herrera <[EMAIL PROTECTED]> wrote:

> 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.


This is neat!
Unfortunately, on the machine that I need this, we are running 7.4.

--


Best Regards,

Tarlika Elisabeth Schmitz


A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad? 

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql