[Django] #30200: Add support for using indexes in update() for ArrayFields.

26 views
Skip to first unread message

Django

unread,
Feb 22, 2019, 4:11:59 AM2/22/19
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: (none)
Type: New | Status: new
feature |
Component: | Version: master
contrib.postgres | Keywords: ArrayField
Severity: Normal | PostreSQL index update
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django supports index lookup for `ArrayField`s (see
[https://docs.djangoproject.com/en/stable/ref/contrib/postgres/fields
/#index-transforms docs]). I think we should support them also in
`update()`, e.g.

{{{
Foo.objects.update(bar_array_field__0='random text')
Foo.objects.update(bar_array_field__0=F('other_related_field'))
}}}

I know that 3rd party packages already support this e.g.
[https://github.com/primal100/django_postgres_extensions
django_postgres_extensions], but IMO we should add this to Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/30200>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2019, 5:55:34 AM2/22/19
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

OK. Seems reasonable.

--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:1>

Django

unread,
Feb 22, 2019, 9:50:42 AM2/22/19
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

See also #24709 for using `QuerySet.update()` without indexes.

--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:2>

Django

unread,
Aug 24, 2019, 4:47:23 AM8/24/19
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: Nasir
| Hussain
Type: New feature | Status: assigned

Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nasir Hussain):

* status: new => assigned
* owner: (none) => Nasir Hussain


--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:3>

Django

unread,
Sep 3, 2019, 6:30:29 AM9/3/19
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: Nasir
| Hussain
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nasir Hussain):

* has_patch: 0 => 1


Comment:

Created a [https://github.com/django/django/pull/11712 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:4>

Django

unread,
Jan 9, 2020, 6:11:14 AM1/9/20
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: Nasir
| Hussain
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:5>

Django

unread,
Jul 30, 2021, 10:55:01 PM7/30/21
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Abhyudai

Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev

Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Abhyudai):

* owner: Nasir Hussain => Abhyudai
* needs_better_patch: 1 => 0
* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:6>

Django

unread,
Mar 22, 2022, 6:03:06 PM3/22/22
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Ben
| Wozniak

Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ben Wozniak):

* owner: (none) => Ben Wozniak


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:8>

Django

unread,
Mar 12, 2024, 3:18:02 AM3/12/24
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

Django

unread,
Jul 19, 2024, 4:51:28 AM7/19/24
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bhuvnesh):

* cc: Bhuvnesh (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:9>

Django

unread,
Feb 8, 2025, 7:50:09 AMFeb 8
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Jacob1507
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob1507):

* owner: (none) => Jacob1507
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:10>

Django

unread,
Feb 13, 2025, 8:45:43 AMFeb 13
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Jacob1507
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/19166 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:11>

Django

unread,
Sep 30, 2025, 3:52:21 PM (17 hours ago) Sep 30
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Jacob1507
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1
* needs_tests: 0 => 1

Comment:

More views are welcome re: whether we should pursue a "left-hand-side"
strategy (as in the PR, making `ArrayField` a compilable) or a "right-
hand-side" strategy with slices and `||`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:12>

Django

unread,
Sep 30, 2025, 4:19:40 PM (16 hours ago) Sep 30
to django-...@googlegroups.com
#30200: Add support for using indexes in update() for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Jacob1507
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: ArrayField | Triage Stage: Accepted
PostreSQL index update |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

Oh fun, I missed the review from the previous attempt :-)

Quoting from
https://github.com/django/django/pull/11712#discussion_r368243765, on a
left-hand-side strategy:

> It feels like the new or adjusted API should call a new
as_update_sql(lhs) method on the lhs that passes the rhs and expect a
(str: sql, Tuple[Any]: params) value to be returned. We have to make sure
that by default this method raises by default so transforms like
update(date__year=2020) fail but they could likely be implemented.

> That would require UpdateQuery.add_update_values to solve the lookups
and resolve both lhs and rhs while disallowing joins and thus aliasing.
You can achieve that by sure making UpdateQuery.alias_cols is always
False.
--
Ticket URL: <https://code.djangoproject.com/ticket/30200#comment:13>
Reply all
Reply to author
Forward
0 new messages