postgresqlquoted-identifier

Is it mandatory to use "" around the table name performing query on PostgreSQL?


I am not so into PostgreSQL and pgAdmin 4 and I have the following doubt.

Following a screenshot of what I can see in my pgAdmin4:

enter image description here

As you can see it is performing this very simple query:

SELECT * FROM public."Example"
ORDER BY id ASC 

The thing that I am not understanding is what is this public name in front of the Example table name. What is it?

I was trying to perform a query in this way but it is not working:

SELECT * FROM Example
ORDER BY id ASC 

It give me a syntax error. I often used MySql and in MySql it is working.

I tried to replace the query in this way:

SELECT * FROM "Example"
ORDER BY id ASC 

and so it is working. So it means that in PosgreSQL database the "" around the table name are mandatory?


Solution

  • The thing that I am not understanding is what is this public name in front of the Example table name. What is it?

    As said in postgres documentation: "By default tables (and other objects) are automatically put into a schema named "public". Every new database contains such a schema."

    So it means that in PosgreSQL database the "" around the table name are mandatory?

    Not really but you need to use it if you are using reserved keywords (such as "user","name"and other)or if your table's name contains uppercase(it's your case) letters. Anyways, in this case if you can it's better change your table's name.