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

Re: another simple SQL question

From: "Daniel T(dot) Staal" <DStaal(at)usa(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: another simple SQL question
Date: 2007-06-25 15:44:20
Message-ID: 58669.63.172.115.138.1182786260.squirrel@MageHandbook.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-sql
On Mon, June 25, 2007 11:28 am, Joshua said:
> 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.

The best way to handle this would actually be to break it _before_ putting
it in to the database.  In fact, you can just have the first and last name
fields then and get the 'fullname' from combining the two.  (Assuming you
don't care about middle names, appliations, or the anything else.)

That's just a comment: I don't know what stage you are in on this database
project.

Assuming you have the database and need to work with it my response to the
above would be to write a perl script to go through and populate the first
and last name fields.  There may be an easier way though.

Daniel T. staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------


In response to

pgsql-novice by date

Next:From: Glenn DavyDate: 2007-06-25 16:02:46
Subject: Re: another simple SQL question
Previous:From: Nicholas BarrDate: 2007-06-25 15:41:02
Subject: Re: another simple SQL question

pgsql-general by date

Next:From: gary jeffersonDate: 2007-06-25 15:47:06
Subject: Re: dynamic table/col names in plpgsql
Previous:From: Nicholas BarrDate: 2007-06-25 15:44:01
Subject: Re: Move a database from one server to other

pgsql-sql by date

Next:From: Glenn DavyDate: 2007-06-25 16:02:46
Subject: Re: another simple SQL question
Previous:From: Nicholas BarrDate: 2007-06-25 15:41:02
Subject: Re: another simple SQL question

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