pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Glenn Davy <glenn@tangelosoftware.net>
To: pgsql-novice@postgresql.org
Subject: Re: another simple SQL question
Date: Tue, 26 Jun 2007 02:14:42 +1000
Message-ID: <200706260214.42493.glenn@tangelosoftware.net> (raw)
In-Reply-To: <467FE784.3060606@blueaxis.com>
References: <467FDF28.8000108@joshuaneil.com>
	<467FE784.3060606@blueaxis.com>

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



view thread (8+ messages)  latest in thread

Message-ID: <200706260214.42493.glenn@tangelosoftware.net>
Permalink:  ../200706260214.42493.glenn@tangelosoftware.net/
Also on:    postgresql.org/message-id/200706260214.42493.glenn@tangelosoftware.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: glenn@tangelosoftware.net, pgsql-novice@postgresql.org
  Subject: Re: another simple SQL question
  In-Reply-To: <200706260214.42493.glenn@tangelosoftware.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox