Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 486E69FB51F; Mon, 25 Jun 2007 12:41:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 52009-05; Mon, 25 Jun 2007 12:41:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 551D79FB530; Mon, 25 Jun 2007 12:41:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from p15195424.pureserver.info (p15195424.pureserver.info [82.165.34.74]) by svr4.postgresql.org (Postfix) with ESMTP id 887165AF888; Mon, 25 Jun 2007 15:41:17 +0000 (GMT) Received: from localhost ([127.0.0.1] helo=www.chuckie.co.uk) by p15195424.pureserver.info with esmtp (Exim 4.43) id 1I2qgY-0003U7-6Q; Mon, 25 Jun 2007 16:41:02 +0100 Received: from mail.orbisuk.com ([62.244.190.66]) (SquirrelMail authenticated user jnb198) by www.chuckie.co.uk with HTTP; Mon, 25 Jun 2007 16:41:02 +0100 (BST) Message-ID: <23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk> In-Reply-To: <467FDF28.8000108@joshuaneil.com> References: <467FDF28.8000108@joshuaneil.com> Date: Mon, 25 Jun 2007 16:41:02 +0100 (BST) Subject: Re: another simple SQL question From: "Nicholas Barr" To: "Joshua" Cc: pgsql-sql@postgresql.org, pgsql-novice@postgresql.org, pgsql-general@postgresql.org Reply-To: nicky@chuckie.co.uk User-Agent: SquirrelMail/1.4.8-1 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: nicky@chuckie.co.uk X-SA-Exim-Scanned: No (on p15195424.pureserver.info); SAEximRunCond expanded to false X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.051 tagged_above=0 required=5 tests=AWL=0.050, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/1442 X-Sequence-Number: 116265 > 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 2: Don't 'kill -9' the postmaster > temp=# create table temptable3 (firstname varchar(32), lastname varchar(32), fullname varchar(32)) without oids; CREATE TABLE temp=# insert into temptable3 (fullname) values ('smith, john'); INSERT 0 1 temp=# insert into temptable3 (fullname) values ('spencer, frank'); INSERT 0 1 temp=# select * from temptable3; firstname | lastname | fullname -----------+----------+---------------- | | smith, john | | spencer, frank (2 rows) temp=# update temptable3 set firstname=trim(substring(fullname from position(',' in fullname) + 1)), lastname=trim(substring(fullname from 0 for position(',' in fullname))); UPDATE 2 temp=# select * from temptable3; firstname | lastname | fullname -----------+----------+---------------- john | smith | smith, john frank | spencer | spencer, frank (2 rows)