Contents
pg_input_error_message()
A function returning the error message for a value invalid for a data type
This entry relates to a PostgreSQL feature which is part of PostgreSQL 16, due to be released in late 2023.
pg_input_error_message()
is a system function which returns the error message which would be emitted if the provided value is invalid for the specified data type.
pg_input_error_message()
was added in PostgreSQL 16.
Usage
pg_input_error_message (string
text
,type
text
) →text
If the provided string is not valid for the specified data type, the message which PostgreSQL would return is emitted, however no ERROR
is raised.
NULL
is returned if the provided string is valid for the specified data type.
pg_input_is_valid()
provides a simple boolean validity test.
Change history
- PostgreSQL 16
- added (commit 1939d262)
Examples
Usage examples for pg_input_error_message()
:
postgres=# SELECT pg_input_error_message('3.14', 'integer'); pg_input_error_message ----------------------------------------------- invalid input syntax for type integer: "3.14" (1 row) postgres=# SELECT pg_input_error_message('3.14', 'text'); pg_input_error_message ------------------------ (1 row) postgres=# SELECT pg_input_error_message('3.14', 'numeric(1,2)'); pg_input_error_message ------------------------ numeric field overflow (1 row)
References
- PostgreSQL 16 documentation: Data Validity Checking Functions