Why is PostgreSQL using 1-based arrays (first element being at index 1) and not 0-based arrays (first element being at index 0)?

  • 1
    I guess this was a design decision. Having said that Oracle has done the same
    – Ed Heal
    Aug 7, 2016 at 22:56

1 Answer 1


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.

  • 2
    Window ranking functions, too, start from 1: ROW_NUMBER(), RANK(), DENSE_RANK(). Aug 8, 2016 at 8:25
  • You're right, I thought position was 0-indexed. Fixing. Aug 8, 2016 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.