Re: Alias field names in foreign data wrapper? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Alias field names in foreign data wrapper?
Date
Msg-id CAKFQuwZe+njCZhQHfEv2F=ti0H+M80gfe_VCSok4cj2SiaqdZA@mail.gmail.com
Whole thread Raw
In response to Re: Alias field names in foreign data wrapper?  (Deven Phillips <deven.phillips@gmail.com>)
List pgsql-general
On Fri, Mar 27, 2015 at 1:55 PM, Deven Phillips <deven.phillips@gmail.com> wrote:
Better example of the problem... My FDW table schema is:

CREATE FOREIGN TABLE liquorstore_backendipaddress (
    id bigint NOT NULL,
    backend_network_id bigint,
    backend_virtual_interface_id bigint,
    address character varying(15) NOT NULL,
    is_gateway boolean NOT NULL,
    is_reserved boolean NOT NULL
)
SERVER edison
OPTIONS (
    dbname 'edison',
    table_name 'liquorstore_backendvirtualinterface'
);


But when I run the following query:

SELECT
    *
FROM liquorstore_backendipaddress

I get an error:

ccedison=# SELECT * FROM liquorstore_backendipaddress;
ERROR:  failed to prepare the MySQL query:
Unknown column 'backend_network_id' in 'field list'

I still cannot figure out what the problem might be so any help would be GREATLY appreciated.

Thanks,

Deven

On Fri, Mar 27, 2015 at 4:15 PM, Deven Phillips <deven.phillips@gmail.com> wrote:
I am trying out some ideas using FDW, and I have added some FDW tables which access a backend MySQL DB... Unfortunately, I am getting some errors because of fields names with reserved words. I was wondering if there is a way to "alias" a field name when creating the foreign table?

Thanks in advance!!!

Deven


​I'm not seeing where you've provided sufficient information for someone to help you.​

From what I can tell there is not aliasing capability native to the FDW implementation so anything would have to be defined in OPTIONS for the table which is a wrapper-controlled structure.

Depending on the overall needs you typically can use reserved label as identifiers if you surround them with double-quotes.

CREATE ... (
"troublesome column name here" bigint,
...
)

​David J.​

pgsql-general by date:

Previous
From: Deven Phillips
Date:
Subject: Re: Alias field names in foreign data wrapper?
Next
From: zach cruise
Date:
Subject: how would you speed up this long query?