#34255: Annotation/group by with an expression on psycopg3
-------------------------------------+-------------------------------------
Reporter: Guillaume Andreu | Owner: nobody
Sabater |
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: orm postgres | Triage Stage: Accepted
psycopg3 annotation groupby |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
This will be hard to solve as group by aliasing cannot be used since
`year` is stripped from the query. All I can think of right now is doing
something along the lines of
{{{#!python
SELECT
"fail_curve"."id",
ARRAY(
SELECT "json" FROM (
SELECT
EXTRACT(
YEAR
FROM
U0."start_at" AT TIME ZONE $1
) AS "year",
jsonb_build_object(
$2,
"year",
$3,
AVG(U0."value")
) AS "json"
FROM
"fail_point" U0
WHERE
U0."curve_id" = ("fail_curve"."id")
GROUP BY "year"
)
) AS "_baseloads"
FROM
"fail_curve"
WHERE
"fail_curve"."id" = $4
}}}
When a group alias is ultimately masked, similarly to how we've done it
with window functions filtering and value masking.
--
Ticket URL: <https://code.djangoproject.com/ticket/34255#comment:2>
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/01070185a7583a1e-40c0cbe1-16e8-4c4e-a10d-c2a742658dae-000000%40eu-central-1.amazonses.com.