tags:

views:

37

answers:

3

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.

+1  A: 

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

SqlACID
Workes, but I can't see why I can't just use the regular name without quotes.
Rhubarb
probably because Name is a reserve word.
Leslie
And also for the reason explained by George (lowercasing).
bortzmeyer
A: 

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

akf
Sorry I used Name as an example, my real field is not a keyname. I suspect it's a casing issue, but I used the same case shown in the GUI.
Rhubarb
+1  A: 

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
George