Re: UNICODE and SQL

From: "Marco Roda" <MarcoRoda(at)amdosoft(dot)com>
To: "Ian Barwick" <barwick(at)gmx(dot)net>, "Achilleus Mantzios" <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: UNICODE and SQL
Date: 2003-05-06 09:05:46
Message-ID: 000301c313ae$ae3a27f0$0301a8c0@amdosoft.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

That's OK!
I will use the SQL variable CLIENT_ENCODING.

SET CLIENT_ENCODING TO 'LATIN1'; /* for German */
or:
SET CLIENT_ENCODING TO 'LATIN2'; /* for Croatian */

that is the same as psql's \encoding.

Thanks a lot!
Marco Roda

-----Original Message-----
From: Ian Barwick [mailto:barwick(at)gmx(dot)net]
Sent: Monday, May 05, 2003 6:49 PM
To: Achilleus Mantzios
Cc: Marco Roda; pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] UNICODE and SQL

On Monday 05 May 2003 22:24, Achilleus Mantzios wrote:
> On Mon, 5 May 2003, Ian Barwick wrote:
> > On Monday 05 May 2003 15:34, Marco Roda wrote:
> > > Hallo,
> > >
> > > I need to use SQL to insert some language specific characters into
> > > tables. In particular I am using German and Croatian specific
> > > characters. The database is created with UNICODE encoding.
> > > For instance, when trying to run from psql:
> > >
> > > INSERT INTO test VALUES (1,'Urlaubslite für nächstes Jahr');
> > >
> > > I get the following error:
> > >
> > > ERROR: Invalid UNICODE character sequence found (0xfc7220)
> > >
> > > because of 'ü' and 'ä'.
> >
> > What is your psql client encoding set to? Possibly you need
> > to set it to LATIN1.

or LATIN2 (?) for the Croatian characters.

> The UTF8 version of Latin1 is Latin1 itself,
> but german and iso8859-2 serbocroatian are
> non Latin1 (high ASCII) chars.

In PostgreSQL "LATIN1" is ISO 8859-1, see:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=multibyte.ht
ml
Unicode Latin 1 (characters 160-255) happens to be the same as ISO 8859-1,
but in UTF-8 is represented as 2 bytes.

Setting psql's \encoding to LATIN1 will convert the client's 8-bit ISO
8859-1
characters (presuming this is the case) to UTF-8.

unitest=# \encoding unicode
unitest=# INSERT INTO test VALUES (1,'Urlaubslite für nächstes Jahr');
ERROR: Invalid UNICODE character sequence found (0xfc7220)
unitest=# \encoding latin1
unitest=# INSERT INTO test VALUES (1,'Urlaubslite für nächstes Jahr');
INSERT 19134 1
unitest=# select * from test;
id | val
----+-------------------------------
1 | Urlaubslite für nächstes Jahr
(1 row)
unitest=# \encoding unicode
unitest=# select * from test;
id | val
----+-------------------------------
1 | Urlaubslite für nächstes Jahr
(1 row)

Ian Barwick
barwick(at)gmx(dot)net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rado Petrik 2003-05-06 09:17:47 Problem with Attribute.
Previous Message Mr.F 2003-05-06 08:04:09 Cast type int2vector/array_field to character