Skip site navigation (1) Skip section navigation (2)

Re: variables with SELECT statement

From: Frank Bax <fbax(at)sympatico(dot)ca>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: variables with SELECT statement
Date: 2008-09-05 20:07:15
Message-ID: 48C19173.1020702@sympatico.ca (view raw or flat)
Thread:
Lists: pgsql-sql
Kevin Duffy wrote:
> Within my table there is a field DESCRIPTION that I would like to parse 
> and split out into other fields.
> 
> Within DESCRIPTION there are spaces that separate the data items.  
> String_to_array(description, ‘  ‘) does the job very well.
> 
> I need something like this to work.
> 
>      select string_to_array(description, ' ') as a_desc,   
>             a_desc[0]  as name , a_desc[1]  as type,  a_desc[2]  as 
> size,  from prodlist where type = 'B'



You almost had it ...

select a_desc, a_desc[1] as name, a_desc[2] as type, a_desc[3] as size
from (select string_to_array(description, ' ') as a_desc from prodlist) 
as foo where a_desc[2] = 'B'

In response to

Responses

pgsql-sql by date

Next:From: Kevin DuffyDate: 2008-09-05 20:31:51
Subject: Re: variables with SELECT statement
Previous:From: Kevin DuffyDate: 2008-09-05 19:50:54
Subject: variables with SELECT statement

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group