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 1ldvaA-0007Mk-U9 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 May 2021 13:59:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ldva9-0005We-QE for pgsql-bugs@arkaria.postgresql.org; Tue, 04 May 2021 13:59:25 +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 1ldva9-0005WR-KF for pgsql-bugs@lists.postgresql.org; Tue, 04 May 2021 13:59:25 +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 1ldva7-000600-H3 for pgsql-bugs@lists.postgresql.org; Tue, 04 May 2021 13:59:24 +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 144DxLP43896143; Tue, 4 May 2021 09:59:22 -0400 From: Tom Lane To: cfederico87@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error In-reply-to: <16991-bcaeaafa17e0a723@postgresql.org> References: <16991-bcaeaafa17e0a723@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 04 May 2021 10:53:56 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3896141.1620136761.1@sss.pgh.pa.us> Date: Tue, 04 May 2021 09:59:21 -0400 Message-ID: <3896142.1620136761@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Casting the name of an object to regclass using `name_col::regclass` is very > useful when querying the pg_catalog view to find the relevant information. > This casting does not work if the name of the object to cast is case > sensitive when it comes from a column. This is acting as designed and documented: regclass input conversion acts the same as the regular SQL parser does, which includes case folding of unquoted text. If you have input that should be taken literally, you can apply quote_ident() to it. Note that your sample query has a second issue: it takes no account of schemas, so it'll fail if a view row shows a table that is not in your search_path. Actually-robust solutions to this problem require something like (quote_ident(schemaname) || '.' || quote_ident(indexrelname))::regclass which illustrates why you don't really want regclass to take its input literally: it needs to be able to interpret schema-qualified names. regards, tom lane