0

I use ecpg to query how many pieces of data there are in the table, the code is as follows

EXEC SQL BEGIN DECLARE SECTION;
     long tblCnt;
EXEC SQL END DECLARE SECTION;
EXEC SQL
     SELECT
         COUNT(*)
     INTO
         :tblCnt
     FROM
         MY_TABLE;

If the data in the table is 217991, the query is normal. If it is greater than or equal to 217992, it will be abnormal.

This is the abnormal log (the data in the table is different except for the first column item_id, and the data in other columns are the same)

2022-10-20 08:38:54.571 GMT [1961839] ERROR: invalid value for parameter "client_encoding": "SJIS"
2022-10-20 08:38:54.571 GMT [1961839] DETAIL: Conversion between SJIS and UTF8 is not supported.
2022-10-20 08:38:54.571 GMT [1961839] CONTEXT: while setting parameter "client_encoding" to "SJIS"
2022-10-20 08:38:54.571 GMT [1961838] ERROR: invalid value for parameter "client_encoding": "SJIS"
2022-10-20 08:38:54.571 GMT [1961838] DETAIL: Conversion between SJIS and UTF8 is not supported.
2022-10-20 08:38:54.571 GMT [1961838] CONTEXT: while setting parameter "client_encoding" to "SJIS"
2022-10-20 16:38:54.571 CST [1961825] ERROR: invalid value for parameter "client_encoding": "SJIS"
2022-10-20 16:38:54.571 CST [1961825] DETAIL: Conversion between SJIS and UTF8 is not supported.
2022-10-20 16:38:54.571 CST [1961825] CONTEXT: while setting parameter "client_encoding" to "SJIS"
parallel worker
2022-10-20 16:38:54.571 CST [1961825] STATEMENT: select count ( * ) from MY_TABLE
2022-10-20 16:38:54.572 CST [611663] LOG: background worker "parallel worker" (PID 1961838) exited with exit code 1
2022-10-20 16:38:54.572 CST [611663] LOG: background worker "parallel worker" (PID 1961839) exited with exit code 1

Environment variables set before running

export LANG=ja_JP.sjis
export PGCLIENTENCODING=SJIS

database character set

pgdb=> show server_encoding;
  server_encoding
-----------------
  UTF8

Database version is 13.5

I queried in www.postgresql.jp/document/13/html/multibyte.html that the server UTF8 character set supports conversion to all client character sets. If the character set is wrong, why is there no error in the first line?

count(*) is counted on the server, why is there a character set conversion error?

Please tell me any possible reason, thanks

kldd
  • 39
  • 5
  • Try changing your LANG environment variable to a UTF-8 compatible, like ja_JP.utf8. Check your possible code pages with `$locale -a` – Pepe N O Oct 21 '22 at 19:53
  • @PepeNO There is no error when changing to utf8. Why is count (*) associated with the local character set? I think that when executing the query, the first step is to determine the encoding format between the server and the client, and the second step is to execute the count (*) query. If the first step is wrong, then the document says that utf8 supports the local SJIS character set. Is it wrong? – kldd Oct 24 '22 at 05:37
  • It's not just count, it's about that all communication (that could take place) between client and server has to be in a mutually compatibile character set. – Pepe N O Oct 24 '22 at 06:34
  • @PepeNO Another clue is that there will be no error when there are 217991 rows of data in the table. If there are 217992 rows of data, there will be no error. The error log says that `DETAIL: Conversion between SJIS and UTF8 is not supported` . In fact, the data of 217991 and 217992 are different only in idc. The data of other columns are the same. If it is the reason of character set conversion, it should be wrong at the beginning, not 217992 lines. So I think this is not a problem of character set, Could this be a bug in pgsql itself? – kldd Oct 24 '22 at 08:55

0 Answers0