Re: Question on inserting non-ascii strings

From: Steven Lembark <lembark(at)wrkhors(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Question on inserting non-ascii strings
Date: 2009-05-14 23:39:41
Message-ID: 20090514193941.7346f7ef@bird.wrkhors.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> Which "warnings" are you talking about? I thought you said you had
> plain SQL working OK, but were struggling to pass parameters containing
> UTF-8 encoded characters.
>
> Are you sure that your Perl code is passing the string encoded as UTF8?

Excellent point: Perl will only pass through the
converted UTF8, if I remember to convert it from
unicode!

The earlier version of the database used SQL_ASCII
and took the unicode byte as-is with a nastygram
about trans-ascii byte -- which led me down the
path of E'xxx'. While trying to make that work I'd
accidentally fat-figered out the utf8 conversion
attempting to comment it out.

Character Unicode Code Unicode Name UTF Encoding

(from http://www.nlm.nih.gov/databases/dtd/medline_character_database.html#notes)

use utf8;

x $c = "\x{F8}"

x utf8::encode $c;

x $c
0 'ø' <-- UTF8 for a slashed o.

$sth->execute( $c )

x $d = $dbh->selectall_arrayref( 'select * from foo' );
0 ARRAY(0x18ef0d0)
0 ARRAY(0x18cc1e8)
0 'ø' <-- bytes in correct order

x utf8::decode $d->[0][0]
DB<106> x $d
0 ARRAY(0x18ef0d0)
0 ARRAY(0x18cc1e8)

I'm still not sure whether using UTF8 or unicode is
the best way going forward, but will probably stick
with UTF8 in case I have to deal with any offball
character sets.

thanx

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2009-05-15 00:33:15 Re: Question on inserting non-ascii strings
Previous Message Dave Page 2009-05-14 22:26:12 Re: Where is pg_dump?