Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: cfederico87@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2021-05-04T13:59:21Z
Lists: pgsql-bugs, pgsql-docs
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



Commits

  1. Doc: improve and centralize the documentation for OID alias types.