Re: i have a problem with judge some words contain chinese word! - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: i have a problem with judge some words contain chinese word!
Date
Msg-id 291BF5D7-D3FD-4F9D-9577-A6E433870EC4@seespotcode.net
Whole thread Raw
In response to i have a problem with judge some words contain chinese word!  (shiguoying <shiguoying@yeah.net>)
List pgsql-general
On Mar 30, 2009, at 10:14 , shiguoying wrote:

>
> Hello:
>    I have a problem with juding some words contain chinese word.
>
>    I found that with oracle.but i can't find it in postgresql.
>    oracle? has acsiistr and lengthb to deal with it.i wonna to know
> postgresql how to !
> ???          thx !
>                                                                from
> eagle

You can use regexp_replace to remove sets of charcters and then
compare lengths or even the strings themselves:

SELECT some_text, LENGTH(some_text), re, LENGTH(re), some_text = re as
str_eq, LENGTH(some_text) = LENGTH(re) AS len_eq
   FROM (SELECT some_text, regexp_replace(some_text, $re$[^[:ascii:]]
$re$, '', 'g') as re
          FROM (VALUES ('foo'), ('foo bar baz'), ('foo.bar,baz'), ('foo
案')) AS samples(some_text)) AS s;

   some_text  | length |     re      | length | str_eq | len_eq
-------------+--------+-------------+--------+--------+--------
  foo         |      3 | foo         |      3 | t      | t
  foo bar baz |     11 | foo bar baz |     11 | t      | t
  foo.bar,baz |     11 | foo.bar,baz |     11 | t      | t
  foo案       |      4 | foo         |      3 | f      | f
(4 rows)

Michael Glaesemann
grzm seespotcode net




pgsql-general by date:

Previous
From: Vyacheslav Kalinin
Date:
Subject: Re: Read a CLOB data from an Oracle table and INSERT it into a BYTEA column in Postgres using jdbc?
Next
From: jc_mich
Date:
Subject: PL/PGSQL arithmetic errors