pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
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
Date: Tue, 04 May 2021 09:59:21 -0400
Message-ID: <3896142.1620136761@sss.pgh.pa.us> (raw)
In-Reply-To: <16991-bcaeaafa17e0a723@postgresql.org>
References: <16991-bcaeaafa17e0a723@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> 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





view thread (10+ messages)  latest in thread

Message-ID: <3896142.1620136761@sss.pgh.pa.us>
Permalink:  ../3896142.1620136761@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3896142.1620136761@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cfederico87@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error
  In-Reply-To: <3896142.1620136761@sss.pgh.pa.us>

* 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