Re: Lossy character conversion to Latin-1

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: Nis Jorgensen <nis(at)superlativ(dot)dk>, pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Lossy character conversion to Latin-1
Date: 2006-05-31 22:59:04
Message-ID: 447E1FB8.3060604@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John DeSoi wrote:
>
> On May 31, 2006, at 10:40 AM, John DeSoi wrote:
>
>> Yes! Thanks very much -- I looked at that page several times and
>> missed regexp_replace.
>
>
> Ok, now I know why I missed it. regexp_replace is only in PostgreSQL 8.1
> and later. I'm stuck with 8.0 for hosting at the moment.
>
> I'm sure it is not very efficient, but the plpgsql function below does
> the same job for PostgreSQL versions prior to 8.1.
>

Command Prompt supports 8.1 for PostgreSQL if you need a new environment.

Sincerely,

Joshua D. Drake

> Thanks for the help,
>
>
> John DeSoi, Ph.D.
> http://pgedit.com/
> Power Tools for PostgreSQL
>
>
>
> create or replace function lossy_latin(p_text text)
> returns text as $$
> declare
> t text;
> res text := '';
> ch text := substring(p_text from '[^\\u0000-\\u00FF]');
> pos integer;
> begin
> if ch is null then
> return p_text;
> else
> t := p_text;
> loop
> pos := strpos(t, ch);
> res := res || substr(t, 1, pos - 1) || '?';
> t := substr(t, pos + 1);
> ch := substring(t from '[^\\u0000-\\u00FF]');
> if ch is null then
> res := res || t;
> exit;
> end if;
> end loop;
> return res;
> end if;
> end;
> $$ language plpgsql immutable;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--

=== The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive PostgreSQL solutions since 1997
http://www.commandprompt.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Germán Aracil Boned 2006-06-01 00:50:17 how to create an insert query from PGresult (libpq-fe.h)
Previous Message Tom Lane 2006-05-31 22:49:08 Re: A quick question on CONTRIB package