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:14:42 |
Message-ID: | 200706260214.42493.glenn@tangelosoftware.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Adrián Ribao Martínez | 2007-06-25 16:32:41 | Re: acampada |
Previous Message | Derrick Betts | 2007-06-25 16:04:20 | Re: another simple SQL question |
From | Date | Subject | |
---|---|---|---|
Next Message | Jean-David Beyer | 2007-06-25 16:40:42 | Re: [SQL] another simple SQL question |
Previous Message | Derrick Betts | 2007-06-25 16:04:20 | Re: another simple SQL question |
From | Date | Subject | |
---|---|---|---|
Next Message | Jean-David Beyer | 2007-06-25 16:40:42 | Re: [SQL] another simple SQL question |
Previous Message | Derrick Betts | 2007-06-25 16:04:20 | Re: another simple SQL question |