It's a fairly old question but the answer is now sort of obsolete. Since PostgreSQL version 16 you can use the function pg_input_is_valid() to see if your input is valid for your data type:
SELECT pg_input_is_valid('0', 'integer'); -- returns TRUE
It's a fairly old question but the answer is now sort of obsolete. Since PostgreSQL version 16 you can use the function pg_input_is_valid() to see if your input is valid for your data type:
SELECT pg_input_is_valid('0', 'integer'); -- returns TRUE