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 1nAyQd-0004sW-5g for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 18:14:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAyQb-0002Zn-TK for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 18:14:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAyQa-0002Zd-3C for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 18:14:25 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAyQV-0003hj-Iu for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 18:14:23 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 1DB3B32021B6; Fri, 21 Jan 2022 13:14:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 21 Jan 2022 13:14:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; bh=ai+JGc6Z5rV4yz pbamKArb66uAVlRBqX6oBm1niKVNI=; b=s5GJJ6x/lZQJn3NEvalNxkzMq4EDsC nEhm9BPjQHwd5feYYk2OPQFvizvAMZEVYpbPlx/K0yAQvK18q17/Z/5NUFQ0Nptm foC/gu4z1L3MFCbOVP5kJayNOq2May3Yhj1uVzkFInmvCHWH9evHgvwYZAbzmlTJ asPz0P3A2xvzpAPNpEWZm1Tu1gZAkSNPOE+eifsWM3hmHlfkdLX1y6VsElgVN3Bf c7oY9wbo1RpdsY5QVDCcypcctgcZYMi45Kafny3EF38qIaELb1GVlNX2TdlMrYND a3QVo0FXO46MZ80VEML5UX+MY60VTnN/XNPJA34jXjRM0nbKBRmtxa0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ai+JGc6Z5rV4yzpbamKArb66uAVlRBqX6oBm1niKV NI=; b=ijluwjhTf9ZwmwNe1bIM7aD3HjWZ0RxpSeO887hNIGrccmH7VtZa3eruV QqGex9PHio4Dm87z01PF7m6eZOWgzib1+o99pZKO2Oy8IzQVupd3zQXMDB7MRS1j 5K2pZ6Zav4CDOLCtferPSWm32TYueQQPhq97ThHZyKQ0MJOv2MRfv7kJnDVE1bna tGUnmmg3YhjgrY3k4oqLALRi2tAxhklSlfQp8ZW/YwqGyqUoNch+4TuyT7SaRjWJ UAFar4wmybYWc0jlJdkTOhB4L+XoUpRRj07DEChTso9mAb68LL01/tISAYKEOLZI nJMMWcpUlxsxs5MDigSnza1r4gOQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrvddtgdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeduudefjeetveffhefgudehtdfhvdetkeeiueehfeev veduteekleeuheegudehhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 21 Jan 2022 13:14:13 -0500 (EST) Subject: Re: Using a different column name in a foreign table To: Alanoly Andrews , Tom Lane , Guillaume Lelarge Cc: "pgsql-general@lists.postgresql.org" References: <1192002.1642783906@sss.pgh.pa.us> From: Adrian Klaver Message-ID: <41f945c2-b0b2-12ca-da63-f9cf7d4740d7@aklaver.com> Date: Fri, 21 Jan 2022 10:14:12 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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