Rhubarb
Rhubarb

Reputation: 4003

Basic SQL Select in Postgresql fails

I am doing a select * on a postgresql table, and everything looks good. But if I do:

SELECT Name from People

It says:

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

But the name column shows up during select *. I've tried:

SELECT People.Name from People

as well, with the same result. Am I missing something? It should be pretty easy to do this in any other database.

Upvotes: 3

Views: 1749

Answers (3)

George Silva
George Silva

Reputation: 3484

PostgreSQL converts everything to lowercase.

If you asks for this:

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

SELECT Name FROM People;

You should get all the information, because pgsql converts this to

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

SELECT name FROM people;

If you built your table with pgAdmin and created field with mixed casing, you will need to quote them to be sucessfull, like this:

SELECT "Att1" FROM people

Upvotes: 2

akf
akf

Reputation: 39485

Name is a keyword, so it might not be handled well in this case. The best thing to do would be to alias the table like this:

SELECT Name from Peoplep

and then use the p to select the column:

SELECTp.Namefrom People p

Upvotes: 1

SqlACID
SqlACID

Reputation: 4014

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

Upvotes: 2

Related Questions