pg_input_is_valid()

A function determining whether a value is valid 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_is_valid() is a system function  determining whether the provided value is valid for the specified data type.

pg_input_is_valid() was added in PostgreSQL 16.

Usage

pg_input_is_valid ( string text, type text ) → boolean

true is returned if the input string matches the specified datatype, otherwise false.

Change history

Examples

Usage examples for pg_input_is_valid():

postgres=# SELECT pg_input_is_valid('3.14', 'integer');
 pg_input_is_valid 
-------------------
 f
(1 row)

postgres=# SELECT pg_input_is_valid('3.14', 'text');
 pg_input_is_valid 
-------------------
 t
(1 row)

postgres=# SELECT pg_input_is_valid('3.14', 'numeric(3,2)');
 pg_input_is_valid 
-------------------
 t
(1 row)

postgres=# SELECT pg_input_is_valid('3.14', 'numeric(1,2)');
 pg_input_is_valid 
-------------------
 f
(1 row)

Categories

Data type, System function, Testing

See also

pg_input_error_message()