Re: converting curly apostrophes to standard apostrophes

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: converting curly apostrophes to standard apostrophes
Date: 2005-08-15 23:48:25
Message-ID: 20050815234825.GA57602@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 15, 2005 at 01:48:00PM -0700, CSN wrote:
> db=>select ascii('’');
> ascii
> -------
> 226
>
> db=>select id from news where body ilike '%’%';
> (0 rows)
>
> db=>select id from news where body ilike '%' ||
> chr(226) || '%';
> db'>
> db'>^C
> db=>

What's going on with the last query? The prompt change suggests
that psql is confused with quoting, and the ^C looks like you hit
Control-C to get the regular prompt back. Did you ever run this
query? If it produced no rows then you could widen the search.
Example:

SELECT id FROM news WHERE body ~ '[\200-\377]';

You could use the "string from pattern" variant of substring() to
extract characters in a specific range. If you have PL/Perl then
it would be trivial to extract all of and only the special characters
along with their ASCII codes:

CREATE FUNCTION special_chars(text) RETURNS text AS '
return join(" ", map {"$_:" . ord($_)} $_[0] =~ /[\200-\377]/g);
' LANGUAGE plperl IMMUTABLE STRICT;

SELECT id, special_chars(body) FROM news WHERE body ~ '[\200-\377]';

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moseley 2005-08-16 00:30:08 Re: Sorting by related tables
Previous Message Andrew Dunstan 2005-08-15 23:31:19 Re: Testing of MVCC