0

I have successfully created a table in pgAdmin which generated the code:

CREATE TABLE public."Test3"
(
    "PID" integer,
    "Name" character varying(20),
    PRIMARY KEY ("PID")
)

TABLESPACE pg_default;

ALTER TABLE public."Test3"
    OWNER to postgres;

However when I try to query the table with:

Select * from Test3;

I get the error:

ERROR:  relation "test3" does not exist 
LINE 1: Select * from Test3;
                      ^ 
SQL state: 42P01 Character: 15

Same thing happens if I leave out the TABLESPACE line. Same thing happens if I try to query a table after importing rows from a .csv file. Seems like I must be missing something obvious.

Edit: I am trying to create the table in a database named "ABR"

3
  • 1
    You should really avoid those dreaded quoted identifiers. They are much more trouble than they are worth it. wiki.postgresql.org/wiki/…
    – user1822
    Sep 22, 2020 at 6:53
  • Ah, thanks for the reference. Silly me for thinking of SQL as case-insensitive. Guess I need to get out of the CamelCase habit
    – haresfur
    Sep 22, 2020 at 22:14
  • SQL is case-insensitive - as long as you don't use those dreaded double quotes. postgresql.org/docs/current/…
    – user1822
    Sep 23, 2020 at 6:15

2 Answers 2

2

PostgreSQL implicitly converts all the SQL that you enter into lower case, unless you wrap things in double-quotes in which case you have to get the case exactly right.

Wherever possible, you should avoid needing quotes or other wrapper characters, i.e. don't use special characters in identifier names. It will only come back to bite you.

create table public.test3
( pid integer
, name character varying(20) 
, primary key (pid)
)
1

The quotes, my friend, don't forget the quotes.

Select * from "Test3";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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