How to convert a db in postgreSQL to utf8?

前端 未结 4 1706
太阳男子
太阳男子 2020-12-31 09:08

I\'ve just got a db in postgreSQL for my project and just realized it\'s in SQL_ASCII encoding, which means \"no encoding\" I think.

So what is the simplest way to c

4条回答
  •  时光取名叫无心
    2020-12-31 09:45

    Converting to UTF8 should not damage your data as (I believe) all characters in SQL_ASCII also exist in utf8; they just have different byte codes.

    Your best bet is to re-build your database. That is dump it, create a utf8 database then restore the dump to that new database.

    postgres pg_dump --encoding utf8 main -f main.sql
    createdb -E utf8 newMain
    psql -f main.sql -d newMain
    

    You can then of course rename the databases once you are happy that the new UTF8 one matches your data.

提交回复
热议问题