#35491 closed New feature (invalid)
QuerySet.extra use case. Unnest array and make it lower. and make it an array again.
| Reported by: | june | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 4.2 |
| Severity: | Normal | Keywords: | QuerySet.extra |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I had used extra() for annotating Arrayfield with lower cases and filter out with another array intersection.
Below is what I used for
`
lower_value = [v.lower() for v in value]
numbers = Numeric.objects.extra(
where=[f"ARRAY(SELECT lower(unnest({array_field}))) && %s::text[]"],
params=[lower_value],
)
`
I need to unnest arrayfield first and make each elements lowercase, and make it an Array again.
and then need to check overlay with another array.
Change History (1)
comment:1 by , 17 months ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Version 0, edited 17 months ago by (next)
Note:
See TracTickets
for help on using tickets.
There are multiple ways to achieve that without the usage of
extra.The most straightforward is to use
RawSQLas mentioned in the docs right below the part that mentions using creating a ticket.But you could also use a
FuncIt would also be pretty straightforward to define an
__ioverlaptransform if you wanted to to encapsulate all of that logicIn short, you don't need
extraat all to achieve what you're after. Please refer to the expression documentation and familiarize yourself withRawSQLusage if you want to resort to raw sql usage.