Re: String Manipulation

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Christine Penner <christine(at)ingenioussoftware(dot)com>
Cc: Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: String Manipulation
Date: 2009-06-13 10:45:12
Message-ID: B3E93F0A-4150-4D54-8043-5385977A671F@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jun 13, 2009, at 12:35 AM, Christine Penner wrote:

> Sam,
>
> The problem with making it a numeric field is that I have seen
> things like A123, #123a or 23-233. This is only here to make most
> sorting work better, not perfect. It all depends on how they enter
> the data. Wont the different formats make it harder to convert to a
> number?
>
> I tried your suggestion and haven't had any luck. For a quick test I
> did this:
> select b_lot_or_st_no, substring('1a','^[0-9]+') as TEST from
> F_BUILDINGS
>
> With this I tried using b_lot_or_st_no instead of 1a, I also
> replaced the , with for like they do in the manual. I looked through
> the manual but I'm still stuck.

The above regular expression assumes values start with a number, so it
won't return anything useful for values like 'A123' or '#123a' and
will just return '23' for '23-233'. I don't think Sam intended it to
be used with the values in your database but just to illustrate how a
regular expression could be used.

I think what you want is something like:
select regex_replace(b_lot_or_st_no, '[^0-9]', '', 'g')

This globally replaces everything that's not a number by '',
effectively removing it from the text.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4a33833c759151518024860!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2009-06-13 10:49:16 Re: Maintenance database SQL_ASCII
Previous Message David Fetter 2009-06-13 08:33:59 Re: [GENERAL] Using results from DELETE ... RETURNING