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

Re: another simple SQL question

From: Glenn Davy <glenn(at)tangelosoftware(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: another simple SQL question
Date: 2007-06-25 16:02:46
Message-ID: 200706260202.46681.glenn@tangelosoftware.net (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-sql
On Tue, 26 Jun 2007 01:28:40 am 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.
>

update yourtable set firstname= substring(fullname,1,position(',' in 
fullname)-1) ,lastname= substring(fullname, position(', ' in fullname)+2, 
char_length(fullname));

glenn

> THANKS!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

In response to

pgsql-novice by date

Next:From: Derrick BettsDate: 2007-06-25 16:04:20
Subject: Re: another simple SQL question
Previous:From: Daniel T. StaalDate: 2007-06-25 15:44:20
Subject: Re: another simple SQL question

pgsql-general by date

Next:From: Derrick BettsDate: 2007-06-25 16:04:20
Subject: Re: another simple SQL question
Previous:From: Jason LongDate: 2007-06-25 16:01:29
Subject: Automatic install on windows

pgsql-sql by date

Next:From: Derrick BettsDate: 2007-06-25 16:04:20
Subject: Re: another simple SQL question
Previous:From: Daniel T. StaalDate: 2007-06-25 15:44:20
Subject: Re: another simple SQL question

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