pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nicholas Barr <nicky@chuckie.co.uk>
To: Joshua <joshua@joshuaneil.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-novice@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: another simple SQL question
Date: Mon, 25 Jun 2007 16:41:02 +0100 (BST)
Message-ID: <23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk> (raw)
In-Reply-To: <467FDF28.8000108@joshuaneil.com>
References: <467FDF28.8000108@joshuaneil.com>

> 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)





view thread (8+ messages)  latest in thread

Message-ID: <23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk>
Permalink:  ../23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk/
Also on:    postgresql.org/message-id/23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk

 · 

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: nicky@chuckie.co.uk, joshua@joshuaneil.com, pgsql-novice@postgresql.org, pgsql-general@postgresql.org
  Subject: Re: another simple SQL question
  In-Reply-To: <23992.62.244.190.66.1182786062.squirrel@www.chuckie.co.uk>

* 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