1

I have a Postgres 8.2 database.
The table encode : SQL-ASCII. (I can't change this :( )
Xhtml charset: charset=iso-8859-2.
The files encode is ANSII. (notepad++)

When I show retrieved data with AJAX (jQuery) I must use utf8_encode(). When this data, insert into database, instead of accent letters (öüőűú) I see this &# 245; &# 251; and others.

Question: How can I solve this encode problem?

EDIT This work me:

pg_dump -E LATIN9 alt > alt.sql
createdb -T template0 -E UTF8 new_database
psql -f alt.sql new_database

1 Answer 1

1

I sounds like you're mixing utf8 encoding and html/xml escaping.

To reconfigure the database's encoding setting, the relevant bits say:

The default character set is selected while initializing your PostgreSQL database cluster using initdb. It can be overridden when you create a database, so you can have multiple databases each with a different character set.

As well as:

CREATE DATABASE name
   [ [ WITH ] [ OWNER [=] dbowner ]
       [ TEMPLATE [=] template ]
       [ ENCODING [=] encoding ]
       [ TABLESPACE [=] tablespace ]
       [ CONNECTION LIMIT [=] connlimit ] ]

Edit: per horse's name, you cannot alter the database's encoding, so you may need to dump the schema and data, edit the dump accordingly, and re-create it accordingly.

Sign up to request clarification or add additional context in comments.

3 Comments

You can only specify the encoding during creation of the database. You cannot change it once the database has been created. See the ALTER DATABASE command: postgresql.org/docs/current/static/sql-alterdatabase.html
Unfortunately, I can't drop data(base), It's a company's database.
Sorry, my English knowledge is not perfect, but now, I understand what you advised. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.