Skip to content

Instantly share code, notes, and snippets.

@911992
Created October 30, 2020 23:50
Show Gist options
  • Save 911992/d45b2beb917db31463d6542056408d57 to your computer and use it in GitHub Desktop.
Save 911992/d45b2beb917db31463d6542056408d57 to your computer and use it in GitHub Desktop.
Array indexing Postgresql

suprisingly! index are started from 1 in pgpsql when it's about arrays!, I just realize it, while i was debuging a plpsql func

An more suprising stuff is about NULL when accessing out-of-bound index of an array, well I was expecting errors!

with arr as(
  select array[911,992]::int[] as arr
)
select arr[1] from arr /*returns 911*/
union all
select arr[0] from arr /*return null*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment