Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error
Date
Msg-id 3896142.1620136761@sss.pgh.pa.us
Whole thread Raw
In response to BUG #16991: regclass is not case sensitive causing "relation does not exist" error  (PG Bug reporting form <noreply@postgresql.org>)
Responses RE: BUG #16991: regclass is not case sensitive causing "relation does not exist" error  (Federico <cfederico87@gmail.com>)
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: pg_restore - generated column - not populating
Next
From: Federico
Date:
Subject: RE: BUG #16991: regclass is not case sensitive causing "relation does not exist" error