-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with client encoding for exception messages #37
Comments
This is expected behavior. To avoid the issue, you need to have a proper client encoding. |
What exactly do you mean by this? I have proper client encoding. Should I setup anything special when using pg_background? The texts in SQL are in UTF-8. PostgreSQL is responsible for converting it into specified client encoding. It works well for normal connection, but fails when used from inside pg_background. |
I don't think that's the expected behavior, as it's not what happens if calling the function without pg_background. For instance:
AFAICS the error message is converted to the client encoding in the bgworker, and then the converted data is converted again when re-throwing it, which definitely cannot work. |
No, this is expected behavior. pg_background worker starts a process with all GUCs settings of the current session and keeps the process attached to the session in which the module was called. So, if your session has client_encoding set to Line 822 in 3278c63
|
Sorry, I don't understand you. Expected behavior is to use wrong encoding when run through pg_background and right encoding when run directly? Something smells here. I think rjuju is right. |
No. Expected behavior is to use encoding/GUCs defined in your main session. For example, if you have started a session with client_encoding If you want to avoid this, you could either set the server-side encoding in your main session or use the following command:
Or you could do:
|
Closing this issue. If needed, it can be reopened. |
Your solution is still only a workaround. The real problem is with double encoding into client charset. Unfortunately your workaround does not work, when we want to use procedures with transaction control (commit/rollback), because "SET" clause block this. From doc: a SET clause is attached to a procedure, then that procedure cannot execute transaction control statements (for example, COMMIT and ROLLBACK, depending on the language). |
I think I encountered the same problem here. To be short, this single instruction fails :
|
Some fields of ErrorData are translated back to server encoding before rethrowing the error.
Using PostgreSQL 13.6 and current pg_background worker, all on Debian 10.
There is a problem with handling exception messages with special characters.
I have database in UTF-8 and I am using Czech special characters. It works when all my clients uses also UTF-8 encoding.
But when client uses different encoding and conversion from UTF-8 must be taken, it fails with:
ERROR: invalid byte sequence for encoding "UTF8": 0xe8 0x6b 0x61
Testing using:
If I run client with different encoding, then it fails:
The correct behavior is:
The text was updated successfully, but these errors were encountered: