You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(
WITH RECURSIVE "cte" AS MATERIALIZED (
SELECT DISTINCT
"product"."id", "product"."level", "product"."category_id"
FROM "product"
ORDER BY "product"."id" ASC
)
SELECT 'level' AS "agg_field", ("cte"."level") AS "field_value", COUNT("cte"."level") AS "count"
FROM "cte"
GROUP BY "cte"."level", 2
)
UNION (
WITH RECURSIVE "cte" AS MATERIALIZED (
SELECT DISTINCT
"product"."id", "product"."level", "product"."category_id"
FROM "product"
ORDER BY "product"."id" ASC
)
SELECT 'category_id' AS "agg_field", ("cte"."category_id") AS "field_value", COUNT("cte"."category_id") AS "count"
FROM "cte"
GROUP BY "cte"."status_id", 2
)
ORDER BY 1 ASC, 2 ASC
As you can see, the above code produces two identical CTEs for each queryset. The expected behavior is to use the same CTE for both queries. The expected output is:
WITH RECURSIVE "cte" AS MATERIALIZED (
SELECT DISTINCT
"product"."id", "product"."level", "product"."category_id"
FROM "product"
ORDER BY "product"."id" ASC
)
SELECT 'level' AS "agg_field", ("cte"."level") AS "field_value", COUNT("cte"."level") AS "count"
FROM "cte"
GROUP BY "cte"."level"
UNION
SELECT 'category_id' AS "agg_field", ("cte"."category_id") AS "field_value", COUNT("cte"."category_id") AS "count"
FROM "cte"
GROUP BY "cte"."category_id"
ORDER BY 1 ASC, 2 ASC
Is there any way to use the same CTE for both queries and merge them with UNION?
PS. Django version 5.0, django-cte ver. 1.3.3
The text was updated successfully, but these errors were encountered:
To use the same CTE for both queries and merge them with UNION, I use the following code:
The output of the above code is:
As you can see, the above code produces two identical CTEs for each queryset. The expected behavior is to use the same CTE for both queries. The expected output is:
Is there any way to use the same CTE for both queries and merge them with UNION?
PS. Django version 5.0, django-cte ver. 1.3.3
The text was updated successfully, but these errors were encountered: