Is there a built-in function to truncate values of one type to fit the range of another type? E.g casting a INTEGER
to SMALLINT
. This might fail if the INTEGER
is larger than SMALLINT
can hold. I would like the number to be truncated to the largest possible SMALLINT
in this case.
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
No inbuilt function I’m aware of, you would need to use a case expression to handle the min and max values e.g:
Not built in, but you can convert it
fiddle