I'm wondering if there is a way to use ::regclass
to convert a string
to a pg_class.oid
in a way that respects case sensitivity. Let me give an example. It's often handy to use ::regclass
to get the oid
of a table, e.g. to list all columns of a table
SELECT * FROM pg_attribute WHERE attrelid = 'public.my_table'::regclass
However, ::regclass
implicitly converts the input to all lowercase before doing the search. (This is similar to how PGSQL will interpret table names in SQL commands, if you don't surround them with double quotes.) This means if your table is called MY_table
, then you cannot use casting to ::regclass
to get its oid
.
I know you can use other means, e.g. use pg_class.relname
and pg_class.relnamespace
. This question is specifically about using ::regclass
, because ::regclass
is more convenient (if I can find a way to make it work in a case sensitive way).
I've tried
SELECT * FROM pg_attribute WHERE attreloid = '"public.my_table"'::regclass
but that includes the double-quotes in the name it searches.