Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx8n-0001iF-0A for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 16:51:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAx8l-0008Gx-Qa for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 16:51:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx8l-0008Go-GL for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 16:51:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx8f-00024e-4M for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 16:51:54 +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 20LGpkMI1192003; Fri, 21 Jan 2022 11:51:46 -0500 From: Tom Lane To: Alanoly Andrews cc: "pgsql-general@lists.postgresql.org" Subject: Re: Using a different column name in a foreign table In-reply-to: References: Comments: In-reply-to Alanoly Andrews message dated "Fri, 21 Jan 2022 16:24:14 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1192001.1642783906.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 21 Jan 2022 11:51:46 -0500 Message-ID: <1192002.1642783906@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alanoly Andrews writes: > I see that the syntax for the creation of a foreign table allows you to = use a column name in the FT that is different from the one in the base tab= le. Such a "create foreign table" statement executes successfully and crea= tes the FT. But when I query the FT, I get an error wrt to the column that= had been renamed. See example below: > create foreign table tab1_ft ( > id int, > name char(10) options(column_name 'newname')) > server xxxxxx > options(schema_name 'public', table_name 'tab1'); > select * from tab1_ft; > ERROR: column "newname" does not exist > HINT: Perhaps you meant to reference the column "tab1.name". > CONTEXT: Remote SQL command: SELECT id, newname FROM public.tab1 > So, it seems that the when the remote SQL command is composed, the mappi= ng of 'newname' to the 'name' in the base table does not take effect. Huh? The CONTEXT line shows what was issued to the remote server, and it's very obvious that we *are* asking for "newname", as indeed is also implied by the error issued by the remote. I think you just didn't match the name correctly to the actual name on the remote. regards, tom lane