Re: Using a different column name in a foreign table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alanoly Andrews <alanolya(at)invera(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Using a different column name in a foreign table
Date: 2022-01-21 16:51:46
Message-ID: 1192002.1642783906@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alanoly Andrews <alanolya(at)invera(dot)com> 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 table. Such a "create foreign table" statement executes successfully and creates 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 mapping 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alanoly Andrews 2022-01-21 17:02:44 RE: Using a different column name in a foreign table
Previous Message David G. Johnston 2022-01-21 16:48:13 Re: Can commands be typed in to view geometry in PgAdmin?