Why is PostgreSQL using 1-based arrays (first element being at index 1) and not 0-based arrays (first element being at index 0)?
-
1I guess this was a design decision. Having said that Oracle has done the same– Ed HealAug 7, 2016 at 22:56
1 Answer
While I think Postgresql has had arrays since before SQL-99, the SQL-99 standard specifies 1-indexed arrays, and it's consistent with other areas in SQL where the first element is 1 instead of 0.
PostgreSQL actually has support for custom array start indexes, but I strongly advise you not to use it.
-
1Window ranking functions, too, start from 1:
ROW_NUMBER()
,RANK()
,DENSE_RANK()
. Aug 8, 2016 at 8:25 -