3

Should not it be ERROR: relation [“schema name”].["table_name"] does not exist instead? Lots of people use case sensitive relation names with dots and so forth. Eg:

t=# select * from public.t1;
ERROR:  relation "public.t1" does not exist
LINE 1: select * from public.t1;
                      ^
t=# create table "public.t1" (i int);
CREATE TABLE
t=# select * from public.t1;
ERROR:  relation "public.t1" does not exist
LINE 1: select * from public.t1;

I am used to getting this error so much that I did not notice that it is misleading. And yet today I hit it with relation.name and realized that error should not use double quotes like this. Is it intentional or should I address it as a bug?

3
  • I would consider it a bug, because the message is misleading.
    – joanolo
    Jan 16, 2017 at 17:12
  • 2
    Have you tried select * from "public.t1" before creating "public.t1" What is the message in that case? What is your proposed alternative? And why are you discussing this here rather than on an appropriate PostgreSQL community site?
    – Andriy M
    Jan 17, 2017 at 6:54
  • @AndriyM "public.t1" does not exist. I ask here before going to Pg comunity, because I could just miss some obvious point
    – Vao Tsun
    Jan 17, 2017 at 8:04

1 Answer 1

0

You're creating a table with a dot identifier.

CREATE TABLE "public.t1" ( a int );
\d public.t1
Did not find any relation named "public.t1".

But, then if you quote it again there..

\d "public.t1"
   Table "public.public.t1"
 Column |  Type   | Modifiers 
--------+---------+-----------
 a      | integer | 

SELECT table_catalog, table_schema, table_name
FROM information_schema.tables
WHERE table_name LIKE '%t1%';
 table_catalog | table_schema | table_name 
---------------+--------------+------------
 test          | public       | public.t1

So instead use this if you want to be goofy,

SELECT * FROM "public.t1";

Or, simply never quote identifiers.

Quoted identifiers can contain any character other than a double quote itself. (To include a double quote, write two double quotes.) This allows constructing table or column names that would otherwise not be possible, such as ones containing spaces or ampersands. The length limitation still applies.

And, also periods.

This is agianst the convention of PostgreSQL. Unless you're doing something like an automated migration that needs to avoid collisions, I would higly suggest you avoid quoted identifiers entirely.

  • Always create things unquoted.
  • Always references things unquoted.

It's not just special characters either. Quoted identifiers make your schema caps-sensitive. This can make your life needlessly more difficult.

7
  • Hi, thanks for the answer! I understand why I get this error. What I'm saying that ERROR: relation "public.t1" does not exist should be ERROR: relation "public"."t1" does not exist when I select 1 from public.t1. And I'm asking - is it misleading only to me?
    – Vao Tsun
    Jan 17, 2017 at 12:03
  • That's not even a question. You're just polling people? Jan 17, 2017 at 12:04
  • @VaoTsun Yes, I agree. It could be clearer. But, write to hackers and tell them. That message should be unquoted unless quotes are needed. I would suggest wrapping it in something other than quotes. That said, this is totally off platform here. Jan 17, 2017 at 12:06
  • I asked if it is a feature or a bug before reporting it to comunity. I hoped the question was about DBA and could be answered. Sorry If I messed up here.
    – Vao Tsun
    Jan 17, 2017 at 12:32
  • There are thousands of areas where things could be clearer. It's a good suggestion. It could be better. But, it's not "a bug." An error occurred and it's trying to communicate that error with you. Jan 17, 2017 at 21:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.