-
Notifications
You must be signed in to change notification settings - Fork 923
when using 'WITH', errors me relation 'WITH NAME' does not exist
#3543
Unanswered
PorcoRosso85
asked this question in
Q&A
-
If anyone also encount same question and tells me it, I'm so glad.
db/query.sql:102:1: relation "closure" does not exist
-- name: BatchRelation :exec WITH RECURSIVE closure AS ( SELECT id, path_depth, created_at, ancester_user_id, descendant_user_id FROM relation UNION ALL SELECT hex(randomblob(16)) AS id, closure.path_depth + r.path_depth AS path_depth, CURRENT_TIMESTAMP AS created_at, r.ancester_user_id, closure.descendant_user_id FROM closure JOIN relation r ON closure.ancester_user_id = r.descendant_user_id WHERE r.path_depth = 1 ) INSERT INTO relation_batch ( id, path_depth, created_at, ancester_user_id, descendant_user_id, contract_id ) SELECT closure.id, closure.path_depth, closure.created_at, closure.ancester_user_id, closure.descendant_user_id, (SELECT contract_id FROM relation WHERE ancester_user_id = closure.ancester_user_id AND descendant_user_id = closure.descendant_user_id LIMIT 1) AS contract_id FROM closure WHERE NOT EXISTS ( SELECT 1 FROM relation_batch WHERE relation_batch.ancester_user_id = closure.ancester_user_id AND relation_batch.descendant_user_id = closure.descendant_user_id AND relation_batch.path_depth = closure.path_depth );
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I just bumped into the same thing. I was able to reproduce the error in a simpler example:
with hello as ( select 1 as t ) select * from hello where hello.t = 1;
^ This is fine, but nest it into a FROM clause:
select * from ( with hello as ( select 1 as t ) select * from hello where hello.t = 1 ) j;
queries/summary.sql:88:1: relation "hello" does not exist
exit status 1
It's a silly query but reproduces the issue. Both queries execute fine against my Postgres instance. There may be some shenanigans to make sqlc happy with it, but unclear what 🤔
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment