Postgres `coalesce` errors with multiple types
The Postgres function coalesce
takes a variable number of arguments and returns the first non-null argument.
But if you include a number and a string, then Postgres throws an error.
Coalesce will try to coerce value to the type of the first argument if possible.
Mysql behaves a bit differently, it allows values of different types.
The postgres way makes a bit more sense to me. What is the type of a column if there are multiple possible types? Is it always a string? But I wanted a number? I feel like the additional type safety will help catch errors a bit earlier.
Tweet