Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wI5Sf-007mH3-1u for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Apr 2026 14:00:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wI5Se-003lcF-2V for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Apr 2026 14:00:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wI5Se-003lc7-1Z for pgsql-hackers@lists.postgresql.org; Wed, 29 Apr 2026 14:00:20 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wI5Sc-00000003M2k-11b4 for pgsql-hackers@lists.postgresql.org; Wed, 29 Apr 2026 14:00:19 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4891e86fabeso141049125e9.1 for ; Wed, 29 Apr 2026 07:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777471215; cv=none; d=google.com; s=arc-20240605; b=UzLdO0xA9UwpZKDOBJLObfmPt4HxOVvfYRhNOVougNqCZ9MEX8On21nxSAnuXxbJit XO/EzAWuo3bhGBOO1iUVAUV16ns4GyN/3NSworeHRRZuu7FwTtYN3g8GLbJyRiBWySp/ c72gEo7hGWUSJNAH9QoxE4F+xXJp3H40o8GLxhFhOEBxsU9D1+zSB1T1Wk6l+tJQ7+dX gdwSWarSwj0mHsHmZAtvvRtz7c/PGpANCaa2ri0IIu8Nle0yCxtmCbpfgXxHxXSzV/x6 WqOKqKnPXRhIoWeJ59+VAS3nsP0blAimVi3quELpMIjrswz79830YNIUL4n+utviDQC2 PSJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7ePWqTmAkyDvMagghWG8cX0m8PkZvliAMFSWKY9RLDQ=; fh=PDhzRmLFhJQgKl2kpY6iqaoiggk+rKjB8rXL7ERgOws=; b=A2E0BjnEm/syJswSzcORqXRXWkI1ZP6F+BDckjW2M/kLOUG2ByAWf4foJW+rHB6tUi o5fjL88G0DyXEPSvNJNrEkwXSqRvIQAT5rAvKdlBCwM0Ol+bUHoTpuBzdcKHxFKEd948 o/lp31K05YAHSE94eTFKmuTixbN8mzawrpEHIYZ5z6NQl/KIMqcXq5I0HmpOBAOZFS7y vyZoXRIN+HSqGXmZWzOKlG1rxJJ4R+kcCqVdaL/pMCgarLv+LRD/JShLRST9pMGh8Q9A 0UlKr7BPoinnQaM/9CbIuANQnRduP7B1RL1WG4JLJBJTJbRlZq65Gh72Rj/QAwJZYPrk KXFw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777471215; x=1778076015; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7ePWqTmAkyDvMagghWG8cX0m8PkZvliAMFSWKY9RLDQ=; b=LpBnBkgnjfEXksBFifrkMqdMbgzR9decKdalCm7R7+bbCMlADvZmRRXmaAqOWlfqYe XQl5YJrfpzs6Wx3uCVeYaiaaxrEiprU6ux6T6+fk9oIOcmkfZ0XrUy9IMHLFTyfjPGJU JMWBQMLSdjGFL8bQptqAk+ZrDzDPEh4aN9ZRrVtK+IHwSAOwWTWcB9ilxnqfpaUuhi+F kmhizXimtGPBeeUDHU0c9H+Xy2Y9Y1a9kyMMvehDZsKytV7qp/SCbESJnV4+tR46i4Jw FIQRBJmSn5HxpUMwRbiTVb/xdtlQgZd1zg6djrDhurY+mIvlAc5dOZjDbjCeVT1vPkKe T3ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777471215; x=1778076015; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7ePWqTmAkyDvMagghWG8cX0m8PkZvliAMFSWKY9RLDQ=; b=kNmt8okHhiwhXbHa8cJxlcopcMT85Nlhu14udCkaQqxcLgCby9eh9M8fZdXz1YeZBx JSd+cNUu2DJo6R0Z9uvqVSHBt4w+r2UhLN1Xji8ypu3L+gWviOSE9Nz8M8xXn+Um+qul D4qv93qp4L1pPalDqDVWN1Ol5IqJZLNOKj1bSApp6A7X73AaDZdQ5DAvdCB5G4Rl86vJ Pn6H0gQwkE6f70gyE0CNp/U94VY5YS/LCHAud4tpCt7Mh4qBTbynJ01CLyktNqCuWkbu p2lEGOuT+O3pD3mE/3z/QrFDvBVsRVJW9wRPDWZa5IqFoeCZWMNe1UxaF2mECIYjsoet TNcw== X-Gm-Message-State: AOJu0YznW6uoQkgDsC+oJMmk5IawViTnkJFikdyg5d+PftCjV1eF/Nfb 8PXd0bUokm7dtnohvtoSD7JEeo+melIRgPBgJa6fytaFLX0QuJq7q1KPwyNonKqKd8Es//1cCut vZoZz1CHswTVI9Bx+yAc643CIEMoH+e4= X-Gm-Gg: AeBDieuhvDPyIG5tyidn1xC9QvKfcEg+kc9rq4yK7dUS7+ygvgr0ngtt/kNldq/4vTL feQXhk9q+QPcj3wHCRPFYHKz3mgjUx4x5fZEyz5djnpNtJ2t2xaF7OecI/1MyqfC4jWKotmsai9 lLsOTHdrv+CIrU5VoYTH0dVWlfGJHkKQnMRRBcSdlEhu5s98NqT2TWuHWelQrSC5K6H/+AySPP9 vagYfCyItJiasJS7E8AJE0XEtSN1sWmfT8s4QYQmoFuHqd2AXK58ihodgxiqpGrc4GCvx/amN4U MnhYo/u2S6EDJWPJzX3gHqrJQOdJ2F3u2zph0Iy8CK9uvgeR3XbYsFUoGD95fA== X-Received: by 2002:a05:600c:b90:b0:489:1e8a:90b4 with SMTP id 5b1f17b1804b1-48a7b53ca8fmr68619605e9.21.1777471215232; Wed, 29 Apr 2026 07:00:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ashutosh Bapat Date: Wed, 29 Apr 2026 19:30:01 +0530 X-Gm-Features: AVHnY4JAexoal2iL-4z7ccIZvikuBA4vjV5enEb3RbcV64jGACdfg_b1cJtdoEA Message-ID: Subject: Re: [PATCH] Improve error message for graph variable references in subqueries within GRAPH_TABLE To: SATYANARAYANA NARLAPURAM Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Apr 25, 2026 at 10:42=E2=80=AFPM SATYANARAYANA NARLAPURAM 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 ass= uming 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 =3D 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 =3D 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. --=20 Best Wishes, Ashutosh Bapat