#34285: Index transforms on filtered array aggregates produces incorrect SQL
query
----------------------------------+------------------------------------
Reporter: Nils Van Zuijlen | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Simon Charette):
* stage: Unreviewed => Accepted
Comment:
Thanks for the report, it seems the issue lies in `IndexTransform.as_sql`
where me might want to do
{{{#!diff
diff --git a/django/contrib/postgres/fields/array.py
b/django/contrib/postgres/fields/array.py
index 8477dd9fff..6c3b3080d5 100644
--- a/django/contrib/postgres/fields/array.py
+++ b/django/contrib/postgres/fields/array.py
@@ -325,7 +325,7 @@ def __init__(self, index, base_field, *args,
**kwargs):
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
- return "%s[%%s]" % lhs, params + [self.index]
+ return "(%s)[%%s]" % lhs, params + [self.index]
@property
def output_field(self):
}}}
It seems that slicing is suffering from the same issue (e.g.
`director_ids__0_2`)
Would you be interested
[https://docs.djangoproject.com/en/4.1/intro/contributing/ in submitting a
PR with this patch that includes a regression test]?
--
Ticket URL: <https://code.djangoproject.com/ticket/34285#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185e0057ba6-769731c2-a67c-4b3b-ab85-df5825af4cb4-000000%40eu-central-1.amazonses.com.