Re: another simple SQL question - Mailing list pgsql-novice

From Glenn Davy
Subject Re: another simple SQL question
Date
Msg-id 200706260214.42493.glenn@tangelosoftware.net
Whole thread Raw
In response to Re: another simple SQL question  (Derrick Betts <list@blueaxis.com>)
List pgsql-novice
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

pgsql-novice by date:

Previous
From: Derrick Betts
Date:
Subject: Re: another simple SQL question
Next
From: Joshua
Date:
Subject: yet another simple SQL question