I have the following input: ,1,2,3. I'd like to cast it to a int[] in postgres.
The following query works:
select string_to_array('1,2,3', ',')::int[]
-- => "string_to_array" => "{1,2,3}"
But this one doesn't:
select string_to_array(',1,2,3', ',')::int[]
-- => ERROR: invalid input syntax for integer: ""
This is because it tries to cast '' (the first value) to an integer.
How can I ignore the first , (or any extra ,) without an error ?