Thread: Encoding questions

Encoding questions

From
"Pat Maddox"
Date:
My databases all have the default SQL_ASCII encoding.  I read the docs
and it says that you shouldn't use it if you're going to have any
non-ASCII data.  I need to start supporting UTF-8, so it seems I need
to convert my database.  Can I just convert it, or do I need to dump
it, drop it, recreate with UTF-8, and then load the data?

Also is it possible to change the default encoding for databases as
well?  The docs say that you do it with initdb.  Do I have to wipe my
data directory and start over, or is there some way just to change the
default encoding?

Thanks for any help.

Pat

Re: Encoding questions

From
Michael Glaesemann
Date:
On Jul 8, 2007, at 14:09 , Pat Maddox wrote:

> Can I just convert it, or do I need to dump
> it, drop it, recreate with UTF-8, and then load the data?

It depends on what is currently in your (SQL_ASCII) database. If it's
only ASCII data or all non-ASCII data is UTF-8, you should be okay
just dumping the data and loading it into a new database with UTF8
encoding.

If this isn't the case, you'll need to clean the dump somehow,
probably using iconv.

> Also is it possible to change the default encoding for databases as
> well?

AFAIK, you can't change the default encoding after it's been set by
initdb, but you can set the encoding at database creation time. See
the CREATE DATABASE or createdb documentation on how to do this.

Michael Glaesemann
grzm seespotcode net