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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: another simple SQL question



hey joshua

On Tue, 26 Jun 2007 02:04:20 am Derrick Betts wrote:
> 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;
>

do you understand the difference between what derrick has put here, and my 
post? Derricks displays the data, mine sets it so that you can then just use 
a  simple select, so make sure you pick which will be useful for your 
usecase. If you can use the update form to populate first and last names, 
then get rid of the 'fullname' field and only populate  the first and last 
names from now on, that would probably also be smart. (we call this 
normalising... getting rid of redundant data)

also note derricks use of TRIM to clean of the white space... thats also a 
good idea i didnt use in my example

glenn
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group