Postgresql basic SQL selection fails

I do select * in the postgresql table and everything looks fine. But if I do this:

SELECT Name from People

It says:

ERROR: column People.Name does not exist
SQL state: 42703
Character: 8

But the name column is displayed during selection *. I tried:

SELECT People.Name from People

with the same result. Am I missing something? This should be pretty easy to do in any other database.

+3
source share
3 answers

Try putting quotes around the column name, i.e. "Name"

+2
source

PostgreSQL converts everything to lowercase.

If you ask for this:

CREATE TABLE People
{
id SERIAL,
Att1 varchar(100)
-- constraints
};

SELECT Name FROM People;

You should get all the information because pgsql converts it to

CREATE TABLE people
{
id SERIAL,
att1 varchar(100),
-- constraints
};

SELECT name FROM people;

pgAdmin , sucessfull, :

SELECT "Att1" FROM people
+2

Nameis a keyword, therefore, in this case, it cannot be well processed. It would be best to use a table alias as follows:

SELECT Name from People p

and then use pto select a column:

SELECT p.Name from People p

+1
source

Source: https://habr.com/ru/post/1746944/


All Articles