pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: jim_esti@hotmail.com
To: pgsql-sql@postgresql.org
Subject: Re: Text manipulation in SQL
Date: Thu, 05 Jul 2001 21:23:42 -0700
Message-ID: <web-81558@davinci.ethosmedia.com> (raw)
In-Reply-To: <f0e3dc0b.0106261359.7ab6b281@posting.google.com>

Jim,

> My little bit of code seems to only extract up to the first blank
> space.  Which would only work correctly if the names where only in
> two
> parts (like Jane, A).
> As I said I would like to return the NAME column in two parts (the
> letters to the right of the right most blank, and the other half).
> It seems a little trick to me.
> Anyone have any advice, hints, or solutions?

You're on exactly the right track.  Just extrapolate out the approach
you have already taken.  For example, if the names were uniformly in the
form:

Last, Initials
James, A. G. P.

Then you can easily break off the parts as you have started, you just
need to fudge the cutoff points a little:

SUBSTR(Name,1,((INSTR(', ',1,1) - 1))

Which should give you:

Last  (without comma or trailing space)
James

Then to grab the initials:

SUBSTR(Name,(INSTR(', ',1,1)+2))

Which will give you:

Initials (without comma or space).
A.G.P.

Of course, this would all be better placed in a PL/pgSQL function so
that you could test to see if the string contained ', ' before breaking
it up, look for NULL, etc.  How about posting the functions when you
have them finished?

Finally, I hope that you are doing this string parsing for *conversion*
purposes.  If you are designing a database to hold personal information,
*create seperate fields for the parts of the name!*  This is much better
DB design, and will save you many headaches in the future.  

Of course, I do realize that one doesn't always have design control when
dealing with legacy systems ...

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco







view thread (3+ messages)

Message-ID: <web-81558@davinci.ethosmedia.com>
Permalink:  ../web-81558@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-81558@davinci.ethosmedia.com

 · 

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: josh@agliodbs.com, jim_esti@hotmail.com
  Subject: Re: Text manipulation in SQL
  In-Reply-To: <web-81558@davinci.ethosmedia.com>

* 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