8

I used pg_restore to load my postgres db with a dump file. I connected to my db with my user :

sudo -u arajguru psql dump

select current_user;
 current_user 
--------------
 arajguru

Now I was able to see all the newly created tables:

dump=> \dt
               List of relations
 Schema |       Name        | Type  |  Owner   
--------+-------------------+-------+----------
 public | Approvals         | table | arajguru
 public | Approvers         | table | arajguru
 public | Conditions        | table | arajguru
 public | Entities          | table | arajguru
 public | EntityDefinitions | table | arajguru
 public | Projects          | table | arajguru
 public | Rules             | table | arajguru
 public | run_history       | table | arajguru
(8 rows)

But when I try to fire a select * query, it gave me this error:

dump=> select * from Approvals;
ERROR:  relation "approvals" does not exist
LINE 1: select * from Approvals;

What can be the reason for this error? Please help.

13

You created your tables with double quotes, and now the names are case sensitive.

As documented in the manual "Approvals" and Approvals are two different names.

Now that you created the table names in a case sensitive manner, you have to use those dreaded double quotes always.

select * 
from "Approvals";

As a general advice: never use double quotes in SQL.

  • 1
    Thanks! Working now. How did you know that the tables were created with double quotes? – Ayushi Rajguru Dec 12 '17 at 7:40
  • 1
    @AyushiRajguru: because the "List of tables" shows them with Upper/lowercase. The only way to achieve that is to use double quotes (as documented in the manual) – a_horse_with_no_name Dec 12 '17 at 7:41
  • 1
    thats some really useful information. Thanks again. – Ayushi Rajguru Dec 12 '17 at 7:44
  • 1
    This saves my day! Thank you a lot 'horse' sensei ! – M-AmineDev FR Jul 31 '18 at 15:17
  • 1
    Oh my god :| Saved me an hour – abzarak May 16 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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