From: Alanoly Andrews <alanolya@invera.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Guillaume Lelarge <guillaume@lelarge.info>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: RE: Using a different column name in a foreign table
Date: Fri, 21 Jan 2022 18:32:22 +0000
Message-ID: <YQXPR01MB3000411D5DD0BDBB6546EBCFAB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <41f945c2-b0b2-12ca-da63-f9cf7d4740d7@aklaver.com>
References: <YQXPR01MB3000CA608DF76835A6881B01AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM>
<1192002.1642783906@sss.pgh.pa.us>
<YQXPR01MB3000706573483AF47BB52302AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM>
<YQXPR01MB30002447A51207071D002993AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM>
<41f945c2-b0b2-12ca-da63-f9cf7d4740d7@aklaver.com>
Thanks Adrian. I was aware of that.
But...in the case of FT definition, the quotes are mandatory after column_name in options. And it is a single quote.
The problem here may be is that the "create foreign table" statement accepts only lower case after options. Remember that the double quotes for the column name in the "select" statement is generated by postgres, not by the end user. If the double quotes were not present, the query with the upper case would have worked.
A.A.
-----Original Message-----
From: Adrian Klaver [mailto:adrian.klaver@aklaver.com]
Sent: Friday, January 21, 2022 1:14 PM
To: Alanoly Andrews <alanolya@invera.com>; Tom Lane <tgl@sss.pgh.pa.us>; Guillaume Lelarge <guillaume@lelarge.info>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Using a different column name in a foreign table
[Email External/Externe] Caution opening links or attachments/attention lors de l'ouverture de liens ou de pièces jointes.
On 1/21/22 10:04 AM, Alanoly Andrews wrote:
> Following up on my previous message, there was a related problem with
> FT definitions for which I have a workaround. It seems that the new
> column_name after "options" in an FT definition cannot be in upper case.
> See below:
> When I define a foreign table like below, I get an error in the
> subsequent select statement:
> create foreign table scvmgl_rec (
> MGL_CLNT_HOST_NM char(15) options (column_name 'MSG_CLNT_HOST_NM'))
> server pglpolaris12018 options (schema_name 'informix', table_name
> 'sctmsg_rec'); ai01pr00=# select * from scvmgl_rec;
> ERROR: column "MSG_CLNT_HOST_NM" does not exist
> CONTEXT: Remote SQL command: SELECT "MSG_CLNT_HOST_NM" FROM
> informix.sctmsg_rec But when I define the FT as below, there is no
> error in the subsequent "select".
> create foreign table scvmgl_rec (
> mgl_clnt_host_nm char(15) options (column_name 'msg_clnt_host_nm'))
> server pglpolaris12018 options (schema_name 'informix', table_name
> 'sctmsg_rec'); So, apparently postgres transmits the remote query with
> double quotes around the upper-case column name; and such a query
> comes back with "column does not exist". But a double quote around a
> lower-case column name does not produce the error.
> Is this a bug that needs to be fixed? I always thought that table
> names and column names were case-insensitive with regard to SQL's.
You thought wrong:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
'Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case.
Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)'
> A.A.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.
Ce courriel est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite. Si vous recevez ce courriel par erreur, veuillez m'en aviser immédiatement, par retour de courriel ou par un autre moyen.'. If the disclaimer can't be applied, attach the message to a new disclaimer message.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: alanolya@invera.com, adrian.klaver@aklaver.com, tgl@sss.pgh.pa.us, guillaume@lelarge.info
Subject: Re: Using a different column name in a foreign table
In-Reply-To: <YQXPR01MB3000411D5DD0BDBB6546EBCFAB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM>
References: <YQXPR01MB3000CA608DF76835A6881B01AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM> <1192002.1642783906@sss.pgh.pa.us> <YQXPR01MB3000706573483AF47BB52302AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM> <YQXPR01MB30002447A51207071D002993AB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM> <41f945c2-b0b2-12ca-da63-f9cf7d4740d7@aklaver.com> <YQXPR01MB3000411D5DD0BDBB6546EBCFAB5B9@YQXPR01MB3000.CANPRD01.PROD.OUTLOOK.COM>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox