pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Barwick <barwick@gmx.net>
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>
Cc: Marco Roda <MarcoRoda@amdosoft.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: UNICODE and SQL
Date: Mon, 5 May 2003 18:48:45 +0200
Message-ID: <200305051848.45893.barwick@gmx.net> (raw)
In-Reply-To: <Pine.LNX.4.44.0305051822250.17972-100000@matrix.gatewaynet.com>
References: <Pine.LNX.4.44.0305051822250.17972-100000@matrix.gatewaynet.com>

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.html
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@gmx.net




view thread (6+ messages)  latest in thread

Message-ID: <200305051848.45893.barwick@gmx.net>
Permalink:  ../200305051848.45893.barwick@gmx.net/
Also on:    postgresql.org/message-id/200305051848.45893.barwick@gmx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: barwick@gmx.net, achill@matrix.gatewaynet.com, MarcoRoda@amdosoft.com
  Subject: Re: UNICODE and SQL
  In-Reply-To: <200305051848.45893.barwick@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox