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
I'm getting a relation "recursive_table_name" does not exist error when running sqlc generate on a query that has a WITH RECURSIVE subquery.
For instance this query (simplified as a test case) throws a relation "search_tree" does not exist error
-- name: GetLatestVersionWithSubquery :oneSELECT*FROM versions
WHEREversions.idIN (
WITH RECURSIVE search_tree(id, chain_id, chain_counter) AS (
SELECTbase.id, base.idAS chain_id, 0as chain_counter
FROM versions AS base
WHEREversions.previous_version_id IS NULLUNION ALLSELECTv.id, search_tree.chain_id, v.parent_lead_time_estimate_id, v.chain_counter+1FROM versions AS v
INNER JOIN search_tree ONsearch_tree.id=v.previous_version_id
)
SELECT DISTINCTON (search_tree.chain_id)
search_tree.idFROM search_tree
ORDER BYsearch_tree.chain_id, chain_counter DESC
);
But that same recursive CTE query parses fine on its own when it's not in a subquery:
-- name: GetLatestVersion :one
WITH RECURSIVE search_tree(id, chain_id, chain_counter) AS (
SELECTbase.id, base.idAS chain_id, 0as chain_counter
FROM versions AS base
WHEREversions.previous_version_id IS NULLUNION ALLSELECTv.id, search_tree.chain_id, v.parent_lead_time_estimate_id, v.chain_counter+1FROM versions AS v
INNER JOIN search_tree ONsearch_tree.id=v.previous_version_id
)
SELECT DISTINCTON (search_tree.chain_id)
search_tree.idFROM search_tree
ORDER BYsearch_tree.chain_id, chain_counter DESC;
It seems like something in the SQL parser isn't matching the CTE's name with the auxiliary statement, only when it's nested in a subquery. But the real version of this query that I'm trying to write does run fine against real postgres, so it seems that the syntax is valid.
Relevant log output
query.sql:24:1: relation "search_tree" does not exist
Database schema
CREATETABLEversions (
id BIGSERIALPRIMARY KEY,
name TEXT,
previous_version_id bigintNOT NULL
);
SQL queries
WITH RECURSIVE search_tree(id, chain_id, chain_counter) AS (
SELECTbase.id, base.idAS chain_id, 0as chain_counter
FROM versions AS base
WHEREversions.previous_version_id IS NULLUNION ALLSELECTv.id, search_tree.chain_id, v.parent_lead_time_estimate_id, v.chain_counter+1FROM versions AS v
INNER JOIN search_tree ONsearch_tree.id=v.previous_version_id
)
SELECT DISTINCTON (search_tree.chain_id)
search_tree.idFROM search_tree
ORDER BYsearch_tree.chain_id, chain_counter DESC;
* test: Add case for #2132
* test: Add case for #2152
* test: Mark case for #2152
* test: Add case for #2187
* test: Add case for #2226
* test: Add case for #2364
* test: Add case for #2386
* test: Add case for #2538
* test: Add case for #2644
* test: Add case for #2731
Version
1.20.0
What happened?
I'm getting a
relation "recursive_table_name" does not exist
error when runningsqlc generate
on a query that has a WITH RECURSIVE subquery.For instance this query (simplified as a test case) throws a
relation "search_tree" does not exist
errorBut that same recursive CTE query parses fine on its own when it's not in a subquery:
It seems like something in the SQL parser isn't matching the CTE's name with the auxiliary statement, only when it's nested in a subquery. But the real version of this query that I'm trying to write does run fine against real postgres, so it seems that the syntax is valid.
Relevant log output
query.sql:24:1: relation "search_tree" does not exist
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/fd638d4cd5e89589d00806d8575daa55fd45f28199ffa1365a43d879dd9a5915
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: