Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:40 AM
stevegy
 
Posts: n/a
Default Hi, everyone. can i ask a question for the server side encoding GB18030 and sortorder?

Hi,

I have set up a postgreSQL on a x86 Solaris 10 box with compiling the source code 8.1.4. My application is need to store the characters encoding with GB18030 or GBK. My Solaris box is installed the locale code zh_CN.GB18030 but I fail to initdb -E GB18030 so I have to use the EUC_CN to initdb and create database.

I have published my application since a month and I notice the appcation server report a few jdbc errors that says :
org.postgresql.util.PSQLException: ERROR: character 0xe28094 of encoding "UTF8" has no equivalent in "EUC_CN"
I think the application user input some kind of characters out of range EUC_CN.

I change my developing test db server to UTF-8 use the initdb --encoding=UTF-8 and recreate the testing database with encoding utf-8. And this testing db server is host on a windows box the encoding is 936(GBK). I restore the data from the pg_dump file. It's fine to work and the sort order is fine also. I mean the Chinese GB18030 data column is "order by" correctly. But when i do the same thing on the Solaris box. I found the sort order is worng. I can fix this with a convert function like this: select cname from t_resume order by convert(cname using utf8_to_gb18030); on the Solaris box. After I use the convert function the order is correct for the Chinese characters.

I think I can change all of my sql in the application to fit this behavior. But when i run the same sql on the windows box. I get the error message: ERROR: could not convert string to UTF-16: error 1113. I stick on it!

I dig on the web and this mail archives but nothing helps. I take a look of the 8.2 beta document in the section "Character Set Support". And I find the table of "Server Character Sets" add a new column Server Support, but the GBK and GB18030 is "not support".

So, how can I fix this issue? any ideas? Thank you everyone.



Steve Yao stevegy (at) 126 (dot) com


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:40 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: Hi, everyone. can i ask a question for th e server side encoding GB18030 and sort order?

On Tue, Oct 03, 2006 at 04:16:36PM +0800, stevegy wrote:
> I have published my application since a month and I notice the appcation server report a few jdbc errors that says :
> org.postgresql.util.PSQLException: ERROR: character 0xe28094 of encoding "UTF8" has no equivalent in "EUC_CN"
> I think the application user input some kind of characters out of range EUC_CN.


That's what the message implies, yes.

> I change my developing test db server to UTF-8 use the initdb
> --encoding=UTF-8 and recreate the testing database with encoding
> utf-8. And this testing db server is host on a windows box the
> encoding is 936(GBK). I restore the data from the pg_dump file. It's
> fine to work and the sort order is fine also. I mean the Chinese
> GB18030 data column is "order by" correctly. But when i do the same
> thing on the Solaris box. I found the sort order is worng. I can fix
> this with a convert function like this: select cname from t_resume
> order by convert(cname using utf8_to_gb18030); on the Solaris box.
> After I use the convert function the order is correct for the Chinese
> characters.


Sortigng is provided by the OS. If your OS can't sort UTF-8, postgres
won't either. But you must make sure that the encoding you specify
during install matches the locale, otherwise funny things happen. You
can't just pick a locale and encoding and expect it to work.

My guess is you have some incompatability there.

> I think I can change all of my sql in the application to fit this
> behavior. But when i run the same sql on the windows box. I get the
> error message: ERROR: could not convert string to UTF-16: error 1113.
> I stick on it!


Windows has yet another way of sorting. Again, make sure the locale
selected matches the encoding you select.

> So, how can I fix this issue? any ideas? Thank you everyone.


Find the locales you're using and make sure they match the encoding
everywhere...

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFImrdIB7bNG8LQkwRAhkQAJ9wV8R3CeSElFc0Ugl18X a7fwn/sgCeMAbI
nItAWvkQcBCdpxouAQEllI8=
=mxE4
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:40 AM
stevegy
 
Posts: n/a
Default Re: &nbsp;&nbsp;Hi,&nbsp;ever

Hi,

Thank you for your reply.
I guess you mean right. I am continuing find the solution now.
I print all the current locale on my solaris here:
=======================================
-bash-3.00# locale
LANG=zh_CN.GB18030
LC_CTYPE="zh_CN.GB18030"
LC_NUMERIC="zh_CN.GB18030"
LC_TIME="zh_CN.GB18030"
LC_COLLATE="zh_CN.GB18030"
LC_MONETARY="zh_CN.GB18030"
LC_MESSAGES="zh_CN.GB18030"
LC_ALL=
=======================================
My testing database is initdb -E UTF8. And i guess the solaris can not handle the UTF-8 sorting with the LC_COLLATE="zh_CN.GB18030". But i needto prove this.
So i plan to change the locale of my solaris box. I have installed the zh_CN.UTF8 on it. I am looking for a way to change the solaris locale. If this changing need to re-boot machine that I should do this in some not busy time for the live application.

I think I post 2 questions in one post and it's a bad idea. So I post another mail for the convert function error.

Thank you and have a nice day.


-- Steve Yao




-----Ô*ʼÓʼþ-----
·¢¼þÈË:"Martijn van Oosterhout"
·¢ËÍʱ¼ä:2006-10-03 21:51:25
ÊÕ¼þÈË:"stevegy"
³*ËÍgsql-general@postgresql.org
Ö÷Ìâ:Re: [GENERAL] Hi, everyone. can i ask a question for th e server side encoding GB18030 and sort order?


On Tue, Oct 03, 2006 at 04:16:36PM +0800, stevegy wrote:

> I have published my application since a month and I notice the appcation server report a few jdbc errors that says :


> org.postgresql.util.PSQLException: ERROR: character 0xe28094 of encoding "UTF8" has no equivalent in "EUC_CN"


> I think the application user input some kind of characters out of rangeEUC_CN.




That's what the message implies, yes.



> I change my developing test db server to UTF-8 use the initdb


> --encoding=UTF-8 and recreate the testing database with encoding


> utf-8. And this testing db server is host on a windows box the


> encoding is 936(GBK). I restore the data from the pg_dump file. It's


> fine to work and the sort order is fine also. I mean the Chinese


> GB18030 data column is "order by" correctly. But when i do the same


> thing on the Solaris box. I found the sort order is worng. I can fix


> this with a convert function like this: select cname from t_resume


> order by convert(cname using utf8_to_gb18030); on the Solaris box.


> After I use the convert function the order is correct for the Chinese


> characters.




Sortigng is provided by the OS. If your OS can't sort UTF-8, postgres

won't either. But you must make sure that the encoding you specify

during install matches the locale, otherwise funny things happen. You

can't just pick a locale and encoding and expect it to work.



My guess is you have some incompatability there.



> I think I can change all of my sql in the application to fit this


> behavior. But when i run the same sql on the windows box. I get the


> error message: ERROR: could not convert string to UTF-16: error 1113.


> I stick on it!




Windows has yet another way of sorting. Again, make sure the locale

selected matches the encoding you select.



> So, how can I fix this issue? any ideas? Thank you everyone.




Find the locales you're using and make sure they match the encoding

everywhere...



Have a nice day,

--

Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

> From each according to his ability. To each according to his ability tolitigate.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:40 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: &nbsp;&nbsp;Hi,&nbsp;ever

On Wed, Oct 04, 2006 at 07:50:12AM +0800, stevegy wrote:
> My testing database is initdb -E UTF8. And i guess the solaris can
> not handle the UTF-8 sorting with the LC_COLLATE="zh_CN.GB18030". But
> i need to prove this.


A locale can only handle one charset, usually the one given by "locale
charset". So if it handles sorting in GB18030 then by definition it
can't handle UTF-8.

> So i plan to change the locale of my solaris box. I have installed
> the zh_CN.UTF8 on it. I am looking for a way to change the solaris
> locale. If this changing need to re-boot machine that I should do
> this in some not busy time for the live application.


The locale is not a global setting. If you set the LANG or LC_ALL
variable, it will change the locale of any program run with that
environment variable. The default is the "C" locale.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFI4HoIB7bNG8LQkwRAmqsAJ4xZ7FQuqEP4OpgNTAcl4 VQlGPYSACgiu4Q
nAbO57xfI//ahiKIfYhswBY=
=xjy5
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 11:40 AM
stevegy
 
Posts: n/a
Default Re: &nbsp;&nbsp;&nbsp;Hi,&nbs

Hi Martijn,

Thank you for the reply.

I think the locale settings is a diffrent in my case, and in the logical way, I guess the locale environs should be used by the program in the system C run-time library for the string operating functions such like comparing or something else like that.

I have login as user name 'postgres' and changed the LANG=zh_CN.UTF-8; export LANG and then the locale command output this:
========================================
-bash-3.00$ locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_ALL=
========================================
So, now i stop the postgres: pg_ctl stop -D ./data_euc_cn and start it use the UTF-8 encoding data directory: pg_ctl start -D ./data_utf8. But thesort result for the Chinese characters is still wrong. And I notice thatthe sort result is diffrent from the LANG=zh_CN.GB18030.

I think I still have not a direct way to solve this. Or, maybe, the postgres uses the locale settings from the other than the current postgres user?
Any suggestions?


-- Steve Yao



-----Ô*ʼÓʼþ-----
·¢¼þÈË:"Martijn van Oosterhout"
·¢ËÍʱ¼ä:2006-10-04 17:42:00
ÊÕ¼þÈË:"stevegy"
³*ËÍgsql-general@postgresql.org
Ö÷Ìâ:Re: [GENERAL] Hi, ever


On Wed, Oct 04, 2006 at 07:50:12AM +0800, stevegy wrote:

> My testing database is initdb -E UTF8. And i guess the solaris can


> not handle the UTF-8 sorting with the LC_COLLATE="zh_CN.GB18030". But


> i need to prove this.




A locale can only handle one charset, usually the one given by "locale

charset". So if it handles sorting in GB18030 then by definition it

can't handle UTF-8.



> So i plan to change the locale of my solaris box. I have installed


> the zh_CN.UTF8 on it. I am looking for a way to change the solaris


> locale. If this changing need to re-boot machine that I should do


> this in some not busy time for the live application.




The locale is not a global setting. If you set the LANG or LC_ALL

variable, it will change the locale of any program run with that

environment variable. The default is the "C" locale.



Have a nice day,

--

Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

> From each according to his ability. To each according to his ability tolitigate.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-09-2008, 11:41 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: &nbsp;&nbsp;&nbsp;Hi,&nbs

On Wed, Oct 04, 2006 at 09:45:26PM +0800, stevegy wrote:
> So, now i stop the postgres: pg_ctl stop -D ./data_euc_cn and start
> it use the UTF-8 encoding data directory: pg_ctl start -D
> ./data_utf8. But the sort result for the Chinese characters is still
> wrong. And I notice that the sort result is diffrent from the
> LANG=zh_CN.GB18030.


You need to do more to change the encoding of a database. The encoding
is fixed at cluster-creation time, so you need to run initdb again to
actually change the locale/encoding.

Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFI8a9IB7bNG8LQkwRAjtrAJ43OnbxDqeGSRo8uxB9vf PSSL6xvACcCDIc
mxWL9sZAy75TeZaMAvIGf80=
=GNaY
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-09-2008, 11:41 AM
stevegy
 
Posts: n/a
Default Re: &nbsp;&nbsp;&nbsp;&nbsp;H

Hi Martijn,

I have changed the locale to LANG=zh_CN.UTF-8;export LANG first, stop the pgsql, and issue the command:
initdb -D ./data -E UTF8 --locale=zh_CN.UTF-8 --lc-collate=zh_CN.UTF-8 -U postgres -W
so i get a fresh new data cluster in this ./data, then I pg_ctl start -D ./data, psql to create the utf8 encoding database:

CREATE DATABASE "Recruit"
WITH OWNER = recruit
ENCODING = 'UTF-8'; -- the owner has been created before this sql

pg_restore -d Recruit ./backup/r2.tar

psql and \c Recruit
\encoding gb18030
-- i will not read the Chinese characters in client mode without this setting on my solaris 10, maybe there's something about the font mapping.

select cname from t_resume order by cname;
and then i get the wrong order result.

I really want to know why the server side encoding for GB18030 is not supported?


Thank you.



-- Steve Yao



-----Ô*ʼÓʼþ-----
·¢¼þÈË:"Martijn van Oosterhout"
·¢ËÍʱ¼ä:2006-10-04 22:35:41
ÊÕ¼þÈË:"stevegy"
³*ËÍ:"pgsql-general@postgr"
Ö÷Ìâ:Re: [GENERAL] Hi,&nbs


On Wed, Oct 04, 2006 at 09:45:26PM +0800, stevegy wrote:

> So, now i stop the postgres: pg_ctl stop -D ./data_euc_cn and start


> it use the UTF-8 encoding data directory: pg_ctl start -D


> ./data_utf8. But the sort result for the Chinese characters is still


> wrong. And I notice that the sort result is diffrent from the


> LANG=zh_CN.GB18030.




You need to do more to change the encoding of a database. The encoding

is fixed at cluster-creation time, so you need to run initdb again to

actually change the locale/encoding.



Hope this helps,

--

Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

> From each according to his ability. To each according to his ability tolitigate.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-09-2008, 11:41 AM
Tom Lane
 
Posts: n/a
Default Re: &nbsp;&nbsp;&nbsp;&nbsp;H

"stevegy" <stevegy@126.com> writes:
> I really want to know why the server side encoding for GB18030 is not supported?


Because it overlaps the ASCII character set, ie, it has multibyte
characters in which some of the bytes don't have the high bit set.
That creates too many parsing risks for us to be willing to deal
with it inside the backend.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-09-2008, 11:41 AM
stevegy
 
Posts: n/a
Default Re: &nbsp;&nbsp;&nbsp;&nbsp;&

Hi Tom,

Thank you for your reply.

I think the character map is a problem. So I see the choices for the Chinese user is:
1. use the EUC_CN
2. use the UTF-8
The first choice is what i'm using and the problem is clear to me. I can not store some special characters into the PostgreSQL with this encoding because the character is out of range.
The second what i am testing now still in some strange issue for the sorting order.

So, any other choice for continuing use the PostgreSQL in my situation?


-- Steve Yao






-----Ô*ʼÓʼþ-----
·¢¼þÈË:"Tom Lane"
·¢ËÍʱ¼ä:2006-10-05 09:50:56
ÊÕ¼þÈË:"stevegy"
³*ËÍ:"martijn van oosterhout" ,"pgsql-general@postgr"
Ö÷Ìâ:Re: [GENERAL] H


"stevegy" <stevegy@126.com> writes:
> I really want to know why the server side encoding for GB18030 is not supported?


Because it overlaps the ASCII character set, ie, it has multibyte
characters in which some of the bytes don't have the high bit set.
That creates too many parsing risks for us to be willing to deal
with it inside the backend.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-09-2008, 11:44 AM
stevegy
 
Posts: n/a
Default Re: Hi, For the UTF-8 encoding

Hi Martijn,

I had changed my Solaris locale setting to zh_CN.UTF-8. I modified the /etc/default/init LANG=zh_CN.UTF-8 and reboot. initdb a new database usedthe encoding UTF8, but the sort order is wrong on the Solaris.

I dig into the TODO list on the postgreSQL web site. The Multi-Language Support ssection I found some resource like this: http://archives.postgresql.org/pgsql...9/msg00662.php

I guess the encoding of UTF-8 support is not stable right now in PostgreSQL. But, on my windows box, 8.1.4 handle the utf8 sorting good. What can I do now? waiting for some kind of patch?


-- Steve Yao






-----Ô*ʼÓʼþ-----
·¢¼þÈË:"Martijn van Oosterhout"
·¢ËÍʱ¼ä:2006-10-04 17:42:00
ÊÕ¼þÈË:"stevegy"
³*ËÍgsql-general@postgresql.org
Ö÷Ìâ:Re: [GENERAL] Hi, ever


On Wed, Oct 04, 2006 at 07:50:12AM +0800, stevegy wrote:

> My testing database is initdb -E UTF8. And i guess the solaris can


> not handle the UTF-8 sorting with the LC_COLLATE="zh_CN.GB18030". But


> i need to prove this.




A locale can only handle one charset, usually the one given by "locale

charset". So if it handles sorting in GB18030 then by definition it

can't handle UTF-8.



> So i plan to change the locale of my solaris box. I have installed


> the zh_CN.UTF8 on it. I am looking for a way to change the solaris


> locale. If this changing need to re-boot machine that I should do


> this in some not busy time for the live application.




The locale is not a global setting. If you set the LANG or LC_ALL

variable, it will change the locale of any program run with that

environment variable. The default is the "C" locale.



Have a nice day,

--

Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

> From each according to his ability. To each according to his ability tolitigate.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:43 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400