Overview
Thefun_errcode function retrieves the human-readable error description for a given PostgreSQL SQLSTATE error code from the tab_error catalog table.
Function Signature
Parameters
The PostgreSQL SQLSTATE error code to lookup (e.g., ‘23505’, ‘22008’, ‘P0001’)
Return Value
Returns aVARCHAR containing the descriptive error message in Spanish, or NULL if the error code is not found in the catalog.
Description
This utility function looks up error codes in thetab_error table and returns the corresponding name_error description. It’s useful for:
- Displaying user-friendly error messages in application interfaces
- Logging detailed error information
- Creating custom error handling workflows
- Debugging database operations
Usage Examples
Basic Error Code Lookup
Using in Error Handling
Application Integration
Common Error Codes
Error Handling
The function returnsNULL if the provided error code does not exist in the tab_error table:
Performance Considerations
- The function performs a simple indexed lookup on
tab_error.cod_error(primary key) - Very fast execution due to primary key index
- Safe to call frequently in application code
Related Documentation
Error Handling Guide
Complete error handling patterns and best practices
Error Catalog Schema
Full reference of the tab_error table structure
Source File
This function is defined in/err/fun_errcode.sql.