0

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.

yılmaz
  • 365
  • 1
  • 14
  • Try `SELECT * FROM public."PRODUCT2"`. – JohnH May 10 '23 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.** – Belayer May 11 '23 at 03:06
  • [From the documentation](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS): *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"` – Zegarek May 11 '23 at 11:04

1 Answers1

0

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"

yılmaz
  • 365
  • 1
  • 14