pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Self-Alias not found (subquery using alias of its outer query)

Open cyrille-arundo opened this issue 4 years ago • 9 comments

https://oguimbal.github.io/pg-mem-playground/

CREATE TABLE my_table (id text NOT NULL PRIMARY KEY, name text NOT NULL, parent_id text);
CREATE INDEX my_table_idx_name ON my_table (name);
CREATE INDEX my_table_idx_id_parent_id ON my_table (id,parent_id);

SELECT * FROM my_table as t1 WHERE t1.name = 'test';
SELECT * FROM my_table as t1 WHERE t1.name = 'test' AND NOT EXISTS (SELECT * FROM my_table as t2 WHERE t2.parent_id = t1.id);

Alias 't1' not found

🐜 This seems to be an execution error, which means that your request syntax seems okay,
but the resulting statement cannot be executed → Probably not a pg-mem error.

*️⃣ Reconsituted failed SQL statement: SELECT *  FROM "my_table" AS "t1"  WHERE (("t1"."name" = ('test')) AND (NOT ("exists"((SELECT *  FROM "my_table" AS "t2"  WHERE ("t2"."parent_id" = "t1"."id") )))))

👉 You can file an issue at https://github.com/oguimbal/pg-mem along with a way to reproduce this error (if you can), and  the stacktrace:

cyrille-arundo avatar Jan 18 '21 10:01 cyrille-arundo

FYI I did not forget you :)

#46 is also having this issue...as I told there, I must refactor a bit some things to make this work, and I didnt find the time to do that yet.

oguimbal avatar Jan 28 '21 16:01 oguimbal

Thanks. There is no rush on my end. I have been watching some of the other issues as well and seeing the progress there. But as a fellow OSS maintainer, I know things take time. Don't feel any unnecessary pressure for my sake :)

AustinGil avatar Jan 28 '21 16:01 AustinGil

Just popping in to +1 this. It's impacting my NestJS project as well. As AustinGil said though, take your time. You are doing an amazing job with this library and I am very grateful for all your effort. ^_^

ghost avatar Feb 15 '21 15:02 ghost

I should've searched existing tickets before submitting mine. Seems test coverage is already done in the new branch, so that's promising. Thanks!

shahyar avatar Feb 22 '21 08:02 shahyar

This is affecting me too 😞

JanisOzolins avatar Nov 05 '21 18:11 JanisOzolins

+1. Has anybody had a chance to fix this? Or find a workaround?

alifarooq0 avatar Apr 11 '22 20:04 alifarooq0

I decided to use this great project, but my migration framework is based on the queries that use subqueries with alias of the outer query.

@oguimbal Seems like the issue is a little stale, is there a chance you can describe the refactoring problem and pass the issue to the community?

luixo avatar Aug 13 '22 16:08 luixo

@oguimbal any chance of fixing this issue? 🙏

mupakoz avatar Oct 27 '23 06:10 mupakoz

would it be possible to edit the sql query in the hook? https://github.com/oguimbal/pg-mem#intercept-queries because then I could probably work around this issue

mupakoz avatar Oct 27 '23 07:10 mupakoz