RefLib

Reference library for AI

Back

postgresql_16:3.6.26.7 Data Validity Checking Functions

PostgreSQL 16 > The SQL Language > Functions and Operators > System Information Functions and Operators > Data Validity Checking Functions

The functions shown in (see functions-info-validity-table) can be helpful for checking validity of proposed input data.

| Function Description Example(s) | | --- | | pg_input_is_valid ( string text, type text ) boolean Tests whether the given string is valid input for the specified data type, returning true or false. This function will only work as desired if the data type's input function has been updated to report invalid input as a “soft” error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly. pg_input_is_valid('42', 'integer') t pg_input_is_valid('42000000000', 'integer') f pg_input_is_valid('1234.567', 'numeric(7,4)') f | | pg_input_error_info ( string text, type text ) record ( message text, detail text, hint text, sql_error_code text ) Tests whether the given string is valid input for the specified data type; if not, return the details of the error that would have been thrown. If the input is valid, the results are NULL. The inputs are the same as for pg_input_is_valid. This function will only work as desired if the data type's input function has been updated to report invalid input as a “soft” error. Otherwise, invalid input will abort the transaction, just as if the string had been cast to the type directly. select * from pg_input_error_info('42000000000', 'integer') message \| detail \| hint \| sql_error_code ------------------------------------------------------+--------+------+---------------- value "42000000000" is out of range for type integer \| \| \| 22003 select message, detail from pg_input_error_info('1234.567', 'numeric(7,4)') message \| detail ------------------------+----------------------------------​------------------------------------------------- numeric field overflow \| A field with precision 7, scale 4 must round to an absolute value less than 10^3. |

Back