Re: another simple SQL question

Поиск
Список
Период
Сортировка
От Glenn Davy
Тема Re: another simple SQL question
Дата
Msg-id 200706260214.42493.glenn@tangelosoftware.net
обсуждение исходный текст
Ответ на Re: another simple SQL question  (Derrick Betts <list@blueaxis.com>)
Список 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 по дате отправления:

Предыдущее
От: Derrick Betts
Дата:
Сообщение: Re: another simple SQL question
Следующее
От: Joshua
Дата:
Сообщение: yet another simple SQL question