From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | cfederico87(at)gmail(dot)com |
Subject: | BUG #16991: regclass is not case sensitive causing "relation does not exist" error |
Date: | 2021-05-04 10:53:56 |
Message-ID: | 16991-bcaeaafa17e0a723@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-docs |
The following bug has been logged on the website:
Bug reference: 16991
Logged by: Federico Caselli
Email address: cfederico87(at)gmail(dot)com
PostgreSQL version: 13.2
Operating system: any
Description:
Hi,
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.
Example using indexes to illustrate:
```sql
begin;
create table example(id serial, value text);
create index "CaseSensitiveIndex" on example (value, id);
create index not_case_sensitive on example (id, value);
select pg_relation_size(indexrelname::regclass) from pg_stat_all_indexes
where indexrelname = 'not_case_sensitive';
select pg_relation_size(indexrelname::regclass) from pg_stat_all_indexes
where indexrelname = 'CaseSensitiveIndex';
rollback;
```
In this example the case the first select using the insensitive
"not_case_sensitive" is correctly casted to regclass, while the second use
using "CaseSensitiveIndex" fails with the error "SQL Error [42P01]: ERROR:
relation "casesensitiveindex" does not exist" suggesting that the case is
not respected by the regclass casting.
While the example makes little sense, since the column "indexrelid" could be
used directly, in many queries the oid of an object is not immediately
available.
Using the "select oid from pg_class where ..." as suggested in the
documentation here https://www.postgresql.org/docs/current/datatype-oid.html
works, but as mentioned in the documentation is not 100% correct.
It think it would be nice if when casting from a column regclass would use
the case sensitive form, like it's possible when using the literal name
directly, like `select '"CaseSensitiveIndex"'::regclass`
Best,
Federico
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2021-05-04 12:25:58 | Re: pg_restore - generated column - not populating |
Previous Message | Andres Freund | 2021-05-04 07:00:10 | Re: BUG #16990: Random PANIC in qemu user context |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-05-04 13:59:21 | Re: BUG #16991: regclass is not case sensitive causing "relation does not exist" error |
Previous Message | Alexander Korotkov | 2021-05-04 01:01:40 | Re: Mention of PG 14 in docs |