-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Summary
Deprecate the use of PQgetResultFromPGconn() for error extraction and instead rely on PQerrorMessage() with a new structured format to provide consistent and parseable error details.
Why is this change needed?
Using PQgetResultFromPGconn() to fetch error results has been inconsistent. Ultimately, we always fallback to PQerrorMessage(), but its output is just a plain string, which lacks crucial components like SQLSTATE.
Although we can adjust PQsetErrorVerbosity() to include more details, the output still combines everything into a single string. This makes it difficult to reliably extract key components.
Proposed Solution
To address this, we plan to:
-
Patch libpq to introduce two new error verbosity levels:
- PSERRORS_FORMATTED_DEFAULT
- PSERRORS_FORMATTED_VERBOSE
-
Modify
pqBuildErrorMessage3(in fe-protocol3.c) to generate errors using a tagged, length-prefixed format.
This new format will make parsing errors consistent and straightforward.
Example:
-
Old format:
ERROR: duplicate key value violates unique constraint -
New format:
S:5:ERRORC:5:23505M:42:duplicate key value violates unique constraint
From the new format, we can extract:
- S (Severity):
ERROR - C (SQLSTATE):
23505 - M (Message):
duplicate key value violates unique constraint
This approach works well for server-generated errors. For library-generated errors (e.g., connection failures), we'll treat them separately. Any leftover error string, without tags is a library-generated error.