1

I have 2 tables in postgres, product and product2

I cannot query product2

enter image description here

query 2 works well,

query 1 and 3 does not run and gives error "relation does not exist" enter image description here

please help.

3
  • Try SELECT * FROM public."PRODUCT2". Commented May 10, 2023 at 23:15
  • 1
    The table list shows table names PRODUCT2 and product . Since table PRODUCT2 contains upper case letters it must have been created with double quotes ("...") therefore you must always use double quotes when referencing it. The table product does not have any such restriction; it was created without double quotes. Double quotes makes the name case sensitive. So PRODUCT and product refer to the same table, but PRODUCT2 and "PRODUCT2" are different tables. Commented May 11, 2023 at 3:06
  • From the documentation: Key words and unquoted identifiers are case insensitive. Therefore: UPDATE MY_TABLE SET A = 5; can equivalently be written as: uPDaTE my_TabLE SeT a = 5;(...) There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes (").(...) Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. As above: use public."PRODUCT2" Commented May 11, 2023 at 11:04

1 Answer 1

1

I found out that when you query SELECT * FROM public.PRODUCT2, you are actually querying product2 table (with lowercase).

It is like all of the text of your query are converted to lowercase characters before actually run.

The text between double quotes does not converted to lowercase so the below query worked.

SELECT * FROM public."PRODUCT2"

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I find that not very intuitive, the issue puzzled me for a bit

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.