HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Why is postgreSQL using 1-based arrays?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlwhyarraysusingbased

Problem

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

Solution

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.

Context

StackExchange Database Administrators Q#146125, answer score: 10

Revisions (0)

No revisions yet.