| From: | Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> |
|---|---|
| To: | SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH] Improve error message for graph variable references in subqueries within GRAPH_TABLE |
| Date: | 2026-04-29 14:00:01 |
| Message-ID: | CAExHW5t-KDmy1W=CnkxUdEe_hM9a9Lf15fk40Qo7_m=TB1HT6w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, Apr 25, 2026 at 10:42 PM SATYANARAYANA NARLAPURAM
<satyanarlapuram(at)gmail(dot)com> wrote:
>
> Hi Hackers,
>
> When a subquery inside GRAPH_TABLE COLUMNS or MATCH WHERE references a
> graph pattern variable, the error was a confusing "missing FROM-clause
> entry for table". Fix by walking the parentParseState chain in
> transformGraphTablePropertyRef() to detect the graph variable and report
> a clear "cannot be used in a subquery" error instead.
>
>
> Based on the below comment and code in transformRangeGraphTable I am assuming we don't support
> subqueries for now.
>
> /*
> * If we support subqueries within GRAPH_TABLE, those need to be
> * propagated to the queries resulting from rewriting graph table RTE. We
> * don't do that right now, hence prohibit it for now.
> */
> if (pstate->p_hasSubLinks)
> ereport(ERROR,
> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> errmsg("subqueries within GRAPH_TABLE reference are not supported")));
> pstate->p_hasSubLinks = saved_hasSublinks;
We don't support subqueries in GRAPH_TABLE for now.
However, I don't think this is the right fix. Consider a query like
SELECT * FROM GRAPH_TABLE (g1 MATCH (src IS vl1)
COLUMNS (src.vname AS sname,
(SELECT * FROM t1 src WHERE a > (SELECT count(*) FROM v1 WHERE vprop1
= src.vprop1) AS cnt))) gt;
The src referenced in the innermost subquery should be resolved to the
t1 in its outer query. That will happen when the column reference
walks the parser state stack. However, since we call
transformGraphPropertyRef() before trying to resolve a column ref as a
column ref, your changes will throw a premature error "graph pattern
variable reference \"%s\" cannot be used in a subquery". I don't think
that's right. A better fix might be to detect a subquery within
GRAPH_TABLE before transforming the subquery and throw "subqueries
within GRAPH_TABLE reference are not supported" error there. That may
be tricky to do, since parse states created between the parse state
which has graph state and parse state of the subquery all have to
carry a flag indicating the existence of a graph table somewhere up
the stack.
--
Best Wishes,
Ashutosh Bapat
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ashutosh Bapat | 2026-04-29 14:09:41 | Re: [PATCH] Resolve unknown-type literals in GRAPH_TABLE COLUMNS |
| Previous Message | Tom Lane | 2026-04-29 13:58:58 | Re: [BUG?] macOS (Intel) build warnings: "ranlib: file … has no symbols" for aarch64 objects |