Search Postgresql Archives

Re: Regex Replace with 2 conditions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Denisa:

On Mon, Feb 5, 2018 at 2:34 PM, Denisa Cirstescu
<Denisa.Cirstescu@xxxxxxxxxx> wrote:
> I need an SQL function that eliminates all ASCII characters from 1-255 that
> are not A-Z, a-z, 0-9, and special characters % and _  so something like:

Are you aware ASCII is a SEVEN bit code ?

And now, why don't you just write the negated condition, maybe
throwing in a null to avoid it? Do you have codes above 255 which you
do not need replacing?

I.e., something like

SELECT regexp_replace(p_string, E'[^A-Za-z0-9%_]', '', 'g'));

This will also zap \0 and all chars >255 if you are using unicode, if
this is not a problem that's all there is to it.

If you are using it you could throw a null plus a character range from
256 to the largest one, but I doubt this is useful. Which is the
character set of your source data? ( It can NOT be ascii if you are
worried about 128-255, but is it a single byte one or is it unicode or
something wide ? )

Also, it may perform a bit faster if you throw a + after the character
class ( for >1 char runs ).

Francisco Olarte.




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux