pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Vadim Nasardinov <vadimn@redhat.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Selecting on non ASCII varchars
Date: Tue, 4 Oct 2005 17:14:01 -0400
Message-ID: <200510041714.01768.vadimn@redhat.com> (raw)
In-Reply-To: <366C3C4C-7E0A-4154-A02E-8A0B6F016157@broadrelay.com>
References: <19B7E72C-CA44-42AE-803E-E87421EC30F9@broadrelay.com>
<43408C35.6020902@opencloud.com>
<366C3C4C-7E0A-4154-A02E-8A0B6F016157@broadrelay.com>
On Tuesday 04 October 2005 16:16, Jeremy LaCivita wrote:
> Hmmm
>
> so it turns out if i take all my Strings and do this:
>
> str = new String(str.getBytes(), "utf-8");
>
> then it works.
>
> Correct me if i'm wrong, but that says to me that the Strings were
> in UTF-8 already, but Java didn't know it, so it couldn't send them
> to postgres properly.
It's meaningless to ask what encoding a String has. String are
sequence of chars -- they don't have an encoding. The notion of
"encoding" comes into play only when you have to represent a String as
a sequence of bytes.
So, if this returns true for you:
str.equals(new String(str.getBytes(), "utf-8"));
that means your default encoding is either utf-8 or a subset of utf-8,
at least for the characters found in str.
String#getBytes() uses the default encoding which may be specified via
the environment variable LANG on on Unix-like systems.
So, if my default encoding is UTF-8, I get this:
| $ echo $LANG
| en_US.UTF-8
| $ bsh2
| BeanShell 2.0-0.b1.7jpp - by Pat Niemeyer (pat@pat.net)
| bsh % print(System.getProperty("file.encoding"));
| UTF-8
| bsh % str = "Funny char: \u00e8";
| bsh % print(str);
| Funny char: è
| bsh % print(str.equals(new String(str.getBytes(), "utf-8")));
| true
| bsh %
If I change the default encoding to ISO-8859-1, I get this:
| $ env LANG=en_US.iso88591 bsh2
| BeanShell 2.0-0.b1.7jpp - by Pat Niemeyer (pat@pat.net)
| bsh % print(System.getProperty("file.encoding"));
| ISO-8859-1
| bsh % str = "Funny char: \u00e8";
| bsh % print(str);
| Funny char: è
| bsh % print(str.equals(new String(str.getBytes(), "utf-8")));
| false
| bsh %
view thread (7+ messages) latest in thread
Message-ID: <200510041714.01768.vadimn@redhat.com> Permalink: ../200510041714.01768.vadimn@redhat.com/ Also on: postgresql.org/message-id/200510041714.01768.vadimn@redhat.com ·
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 from your mail client; the link fills in the headers below: reply via email Some clients, webmail especially, drop In-Reply-To and References from a link, and the reply then starts a new thread: use the mbox below. To: pgsql-jdbc@postgresql.org Cc: vadimn@redhat.com Subject: Re: Selecting on non ASCII varchars In-Reply-To: <200510041714.01768.vadimn@redhat.com> References: <19B7E72C-CA44-42AE-803E-E87421EC30F9@broadrelay.com> <43408C35.6020902@opencloud.com> <366C3C4C-7E0A-4154-A02E-8A0B6F016157@broadrelay.com> <200510041714.01768.vadimn@redhat.com> * 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