0

I am running into some strange problem in PostgreSQL

$ sudo -u postgres psql Blogging
psql (10.10 (Ubuntu 10.10-0ubuntu0.18.04.1))
Type "help" for help.

Blogging=# \dt
               List of relations
 Schema |         Name          | Type  | Owner 
--------+-----------------------+-------+-------
 public | Blogs                 | table | e
 public | Posts                 | table | e
 public | __EFMigrationsHistory | table | e
(3 rows)

Blogging=# select * from Blogs
Blogging-# ;
ERROR:  relation "blogs" does not exist
LINE 1: select * from Blogs
                      ^

The same problem occurs when I log in as the owner of the tables:

$ psql -U e Blogging
psql (10.10 (Ubuntu 10.10-0ubuntu0.18.04.1))
Type "help" for help.

Blogging=# \dt
               List of relations
 Schema |         Name          | Type  | Owner 
--------+-----------------------+-------+-------
 public | Blogs                 | table | e
 public | Posts                 | table | e
 public | __EFMigrationsHistory | table | e
(3 rows)

Blogging=# select * from Blogs; 
ERROR:  relation "blogs" does not exist

I created the database when running my application which uses Entity Framework, following https://learn.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli. But I had some problem with the application, not sure if they are related to my question here.

Tim
  • 129
  • 1
  • 8
  • "Blogs" is a different name than Blogs https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS - don't create your tables using double quotes: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_upper_case_table_or_column_names –  Jan 10 '20 at 06:56
  • Why didn't \dt show the table names containing double quotes? I create "Blogs" by following https://learn.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli#create-the-database, and how did it add double quotes in the table name? – Tim Jan 10 '20 at 07:00
  • You (or the tools you are using) added the the quotes, Postgres doesn't do that on its own. If you run create table Blogs (...) it will be created in lowercase (as the link to the manual in my previous comment explains) –  Jan 10 '20 at 07:02
  • Why didn't \dt show the table names containing double quotes? – Tim Jan 10 '20 at 07:09
  • I can only guess, but maybe because the developers of psqlthought it's obvious that quotes are needed. Other SQL clients might display that differently –  Jan 10 '20 at 07:11
  • I followed https://learn.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli#create-the-database, I still don't see how the double quotes in the table names were introduced. – Tim Jan 10 '20 at 07:15

0 Answers0