Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.4.0
-
None
Description
Unlike in Snowflake we decided that array_inert() is 1 based.
This means 1 is the first element in an array and -1 is the last.
This matches the behavior of functions such as substr() and element_at().
> SELECT array_insert(array('a', 'b', 'c'), 1, 'z'); ["z","a","b","c"] > SELECT array_insert(array('a', 'b', 'c'), 0, 'z'); Error > SELECT array_insert(array('a', 'b', 'c'), -1, 'z'); ["a","b","c","z"] > SELECT array_insert(array('a', 'b', 'c'), 5, 'z'); ["a","b","c",NULL,"z"] > SELECT array_insert(array('a', 'b', 'c'), -5, 'z'); ["z",NULL,"a","b","c"] > SELECT array_insert(array('a', 'b', 'c'), 2, cast(NULL AS STRING)); ["a",NULL,"b","c"]