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 1vU52A-00GZAL-2s for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Dec 2025 15:26:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vU529-008TBJ-1u for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Dec 2025 15:26:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vU529-008TBB-13 for pgsql-bugs@lists.postgresql.org; Fri, 12 Dec 2025 15:26:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vU527-000MQu-1U for pgsql-bugs@lists.postgresql.org; Fri, 12 Dec 2025 15:26:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5BCFQCtd988550; Fri, 12 Dec 2025 10:26:13 -0500 From: Tom Lane To: Veeranjaneya Vara Prasad Peddireddy cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: Bug in sub-query In-reply-to: References: Comments: In-reply-to Veeranjaneya Vara Prasad Peddireddy message dated "Fri, 12 Dec 2025 10:59:25 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <988548.1765553172.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 12 Dec 2025 10:26:12 -0500 Message-ID: <988549.1765553172@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Veeranjaneya Vara Prasad Peddireddy = writes: > --query 2: > select * from admin.emp where location_id_location=3D108 > and sno in (select dim_id from admin.emp_dimension where location_id_loc= ation=3D108) > --Note2: it returned two records and no error given. > --But if you observe above query 2; the sub-query is not correct. In sub= -query; location_id_location is not present in table admin.emp_dimension. = But same sub-query failed in query 1. This is not a bug, it is behavior required by the SQL standard. If location_id_location is not found among the columns available from the sub-query's FROM clause, it will be treated as an "outer reference" to columns available from the outer query. The usual way to avoid falling into this trap is to always relation-qualify column references, especially in sub-queries. regards, tom lane