Array index in postgres ARRAy
Hi.
When I work with SQLAlchemy and PostgreSQL I find interesting and unobvious nuance:
When using item of array in filter or order_by there are need to use indexes starts from 1 (there are no index 0 in pestgres ARRAY) But, for getting value or values and use it there are need to use indexes starts from zero.
May be would be better change logic of getitem method of sqlalchemy.dialects.postgresql.ARRAY for use one standart of indexes in all situations.
Regards, Alexey Terentev
Comments (12)
-
repo owner -
repo owner I think we'd want to make the zero index adjustment against literal Python values only, not in SQL. like if someone said
table.c.somecolumn[someother_table.c.column](someother_table.c.column)
, assumesomeother_table.c.column
is one-based. Though I think there's lots of potentially untenable situations here if someone really makes heavy use of hybrid behavior in conjunction with array indexing, ultimately in such a situation they may have to build their own comparators to work things out as needed. -
repo owner - changed milestone to 0.9.xx
-
-
https://bitbucket.org/LevonXXL/sqlalchemy/commits/57b6da9d402f164605c7bfe270654725cb604f1f
I did push new commit via rebase and squash - this with changes from comments
-
repo owner should be good, send a pullreq! thanks
-
repo owner - edited description
- changed milestone to 0.9.5
-
Which branch select for create pull-request into?
master or any other?
-
repo owner typically master.
-
repo owner - changed status to resolved
→ <<cset 460465a8749a>>
-
repo owner OK thanks!
-
thank you!
- Log in to comment
yeah especially in terms of SQLAlchemy hybrid attributes. But we can't make this a default change, it has to be a flag. Can you work up a pull request for a feature like this?