You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PostgreSQL compatibility: negative array subscripts should not index from the end #22254
* [fix: return NULL for negative array subscripts in PostgreSQL dialect #22294](https://github.com/apache/datafusion/pull/22294)
Which ties it to the dialect setting
Based on #22252, it seems like it should be tied to the dialect in cases where the behavior is conflicting, and where the postgres behavior subjective (unlike in cases like #22270).
Activity
xiedeyantu commentedon May 16, 2026
take
kumarUjjawal commentedon May 18, 2026
DuckDB:
xiedeyantu commentedon May 18, 2026
DuckDB does indeed work that way, so should we keep it as is? Returning 30 might be a better approach.
kumarUjjawal commentedon May 18, 2026
DuckDB intentionally implements Python-style negative indexing: arr[-1] = last element, arr[-k] = k-th from end, out-of-bounds → NULL. PG returns NULL for negative subscripts (no from-end semantics). DuckDB documents this through examples (['a','b','c'][-1] → 'c').
We can get consensus about which engine to follow for this.
xiedeyantu commentedon May 19, 2026
I'm leaning towards the DuckDB approach and would like to get your thoughts.
kumarUjjawal commentedon May 19, 2026
I agree we should stick to the current approach unless we have some special use case for the change.
xiedeyantu commentedon May 19, 2026
We can wait for Dan's suggestion, and if he agrees, I can close the PR at any time.
xiedeyantu commentedon May 22, 2026
HI @Dandandan , WDYT?
Jefffrey commentedon May 26, 2026
Spark also doesn't tolerate negative indices it seems (though it errors outright). Clickhouse seems to align with DuckDB.
I agree that negative indexing makes sense to me, since I'm also used to how Python treats it.
Jefffrey commentedon May 26, 2026
Another option is this PR:
Which ties it to the dialect setting
ngli-me commentedon Jun 8, 2026
Based on #22252, it seems like it should be tied to the dialect in cases where the behavior is conflicting, and where the postgres behavior subjective (unlike in cases like #22270).