Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1B8A89FB2EE for ; Mon, 25 Jun 2007 13:14:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56450-02 for ; Mon, 25 Jun 2007 13:14:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail10.tpgi.com.au (mail10.tpgi.com.au [203.12.160.147]) by postgresql.org (Postfix) with ESMTP id A3EB29FB464 for ; Mon, 25 Jun 2007 13:14:36 -0300 (ADT) X-TPG-Antivirus: Passed Received: from thrudgelmir.local (60-240-41-118.static.tpgi.com.au [60.240.41.118]) by mail10.tpgi.com.au (envelope-from glenn@tangelosoftware.net) (8.13.6/8.13.6) with ESMTP id l5PGEKDi024797 for ; Tue, 26 Jun 2007 02:14:34 +1000 From: Glenn Davy To: pgsql-novice@postgresql.org Subject: Re: another simple SQL question Date: Tue, 26 Jun 2007 02:14:42 +1000 User-Agent: KMail/1.9.7 References: <467FDF28.8000108@joshuaneil.com> <467FE784.3060606@blueaxis.com> In-Reply-To: <467FE784.3060606@blueaxis.com> Organization: Tangelo Software MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200706260214.42493.glenn@tangelosoftware.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/170 X-Sequence-Number: 19068 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