Closed lephuongbg closed 2 months ago
Adding in_query=True
to the context here would solve this particular issue, but I don't know whether it would cause other regressions.
https://github.com/coleifer/peewee/blob/c5aa497b1365b583bf372fe16f5fc24d07db3e09/peewee.py#L1845
Thanks, this should be fixed now.
SELECT
CASE ("t1"."metadata"->>'price' IS NULL)
WHEN 1 THEN (
SELECT sum("products_recordset"."price" * "products_recordset"."quantity")
FROM jsonb_populate_recordset(NULL::universal.al_items, "t1"."metadata"->'products') AS "products_recordset")
ELSE (CAST(CAST("t1"."metadata"->>'price' AS text) AS double precision) * "t1"."quantity")
END
FROM "orderitems" AS "t1"
Given following example of using a subquery inside a
CASE...WHEN...
expression:Expected:
The desired SQL output should be as follow:
Current output:
An extra alias was added to the subquery, causing invalid syntax.
Database is PostgreSQL.