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
{{ message }}
Repository navigation
A recursive subquery in WHERE clause fails to compile (with incorrect error message.) #3206
sqlc failed to compile a query with a recursive query in the WHERE clause.
Error message: relation "xxx" does not exist
The GetTest1 and GetTest2 queries differ just by WITH RECURSIVE gen and WITH RECURSIVE gen(id) signatures, which are still irrelevant in the given example. Both queries work with Postgres 16.
This bug is significant because the subquery doesn't impact both input, output structures nor query function in the generated code.
Relevant log output
sqlc generate failed.
# package
query.sql:1:1: relation "gen" does not exist
query.sql:23:1: relation "gen" does not exist
Database schema
CREATETABLEparts (
id BIGSERIALPRIMARY KEY,
name textNOT NULL,
category_id BIGSERIAL
);
CREATETABLEpart_categories (
id BIGSERIALPRIMARY KEY,
name textNOT NULL,
parent_id BIGSERIAL
);
SQL queries
-- name: GetTest1 :manySELECT*FROM parts
WHERE category_id = $1OR category_id IN (
WITH RECURSIVE gen AS (
SELECT id, parent_id FROM part_categories WHERE parent_id = $1UNION ALLSELECTchild.id, child.parent_idFROM part_categories child
JOIN gen
ONgen.id=child.parent_id
)
SELECTgen.idFROM gen
LEFT JOIN part_categories parent
ONgen.parent_id=parent.id
);
-- name: GetTest2 :manySELECT*FROM parts
WHERE category_id = $1OR category_id IN (
WITH RECURSIVE gen(id) AS (
SELECT id, parent_id FROM part_categories WHERE parent_id = $1UNION ALLSELECTchild.id, child.parent_idFROM part_categories child
JOIN gen
ONgen.id=child.parent_id
)
SELECTgen.idFROM gen
LEFT JOIN part_categories parent
ONgen.parent_id=parent.id
);
Activity
dandee commentedon Sep 2, 2025
Hi @kyleconroy , do you have any plans to address this issue?
PS: Playground fails if you try to use any sqlc version above 1.25 (500 Internal Server Error.)
dandee commentedon Apr 21, 2026
Friendly poke @kyleconroy : )