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

Re: another simple SQL question

From: Derrick Betts <list(at)blueaxis(dot)com>
To: Joshua <joshua(at)joshuaneil(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: another simple SQL question
Date: 2007-06-25 16:04:20
Message-ID: 467FE784.3060606@blueaxis.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-sql
Try this:
SELECT substr(fullname, 1, position(',' IN fullname)-1) AS first,
   trim(substr(fullname, position(',' IN fullname)+1, length(fullname))) 
AS last
   FROM table_name;

Joshua wrote:
> Ok here is another simple question from a novice....
> 
> Here is what my table looks like
> 
> firstname         lastname         fullname
> ----------       ----------       -----------
>                                              smith, john
>                                              green, susan
>                                              white, jeff
> 
> 
> How can I break the fullname field into firstname lastname fields so it 
> looks like the following:
> 
> firstname      lastname      fullname
> ---------     ---------       ---------
> john             smith             smith, john
> susan           green             green, susan
> jeff               white             white, jeff
> 
> Please let me know. Sorry for such simple novice questions, I appreciate 
> your support.
> 
> THANKS!
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
> 
> 
> 



In response to

Responses

pgsql-novice by date

Next:From: Glenn DavyDate: 2007-06-25 16:14:42
Subject: Re: another simple SQL question
Previous:From: Glenn DavyDate: 2007-06-25 16:02:46
Subject: Re: another simple SQL question

pgsql-general by date

Next:From: Glenn DavyDate: 2007-06-25 16:14:42
Subject: Re: another simple SQL question
Previous:From: Glenn DavyDate: 2007-06-25 16:02:46
Subject: Re: another simple SQL question

pgsql-sql by date

Next:From: Glenn DavyDate: 2007-06-25 16:14:42
Subject: Re: another simple SQL question
Previous:From: Glenn DavyDate: 2007-06-25 16:02:46
Subject: Re: another simple SQL question

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