Hi Man, I made a super simple extension `https://github.com/Z-Xiao-M/pg_pgq2sql` > <https://github.com/Z-Xiao-M/pg_pgq2sql> to get the equivalent SQL of PGQ > queries – it simply calls `pg_get_querydef` after `QueryRewrite` to fetch > the SQL text. > > However, I noticed that some FROM clauses were missing in the generated > SQL statements. >
Good catch. The patch is correct — these RTEs are real FROM clause entries (they're appended to fromlist), so inFromCl should be true. I looked at whether this has any impact beyond pg_pgq2sql: - pg_get_viewdef() deparses the pre-rewrite query, so it outputs the original GRAPH_TABLE(...) syntax — not affected. - pg_dump uses pg_get_viewdef(), so also not affected. So in practice, this only affects code that deparses the post-rewrite query (like your extension). No core code path currently does this for graph table queries. > pni = addRangeTableEntryForRelation(make_parsestate(NULL), > rel, AccessShareLock, > - > NULL, true, false); > + > NULL, true, true); > That said, the fix is clearly correct. As documented in parsenodes.h, inFromCl is false for "RTEs that are added to a query behind the scenes, such as the NEW and OLD variables for a rule, or the subqueries of a UNION." The element table RTEs here are neither — they are genuinely in the FROM clause. Ashutosh, what do you think? Best regards, Henson
