Simple Postgresql Statement - Column Name Does Not Exists

Simple Postgresql Statement - column name does not exists

I would guess:

 SELECT * FROM employee WHERE "lName" LIKE 'Smith'

(note the different quotes; "foo" is a quoted identifier; 'foo' is a string literal)

Also, in most SQL dialects, a LIKE without a wildcard is equivalent to =; did you mean to include a wildcard?

PostgreSQL column 'foo' does not exist

You accidentally created the column name with a trailing space and presumably phpPGadmin created the column name with double quotes around it:

create table your_table (
"foo " -- ...
)

That would give you a column that looked like it was called foo everywhere but you'd have to double quote it and include the space whenever you use it:

select ... from your_table where "foo " is not null

The best practice is to use lower case unquoted column names with PostgreSQL. There should be a setting in phpPGadmin somewhere that will tell it to not quote identifiers (such as table and column names) but alas, I don't use phpPGadmin so I don't where that setting is (or even if it exists).

Postgresql ERROR: column ... does not exist In A Simple Query

The problem was, I was writing string with ", not with '.
When I changed the query like:

select *
from "userGroupUserOrganizations"
where "id" = '9fce8e9b-597a-4100-bb3c-efb86aaa83ae';

it worked

Column doesnot exist error in PostgreSQL command

If you write "tablename.columnname", that is not interpreted as table name and column name, but as a single identifier. Based on the context in a join condition, PostgreSQL expects it to be a column name.

If you use double quotes, you have to quote column and table separately: "tablename"."columnname"

PostgreSQL Column does not exist but it actually does

Try to take it into double quotes - like "Continent" in the query:

SELECT "Continent"
FROM network.countries
...

Column doens't exists in PostgreSQL (WHERE column_name = column_value)

It's as simple as the wrong type of quote marks. You wanted:

SELECT * FROM grades 
WHERE subject = 'latin';

To explain:

  • Single quotes, like 'latin', are the standard way to write a string in standard SQL, and should work on all DBMSes.
  • Double quotes, in Postgres and some other DBMSes, are a way of quoting identifiers - so if your column name had a space in for some reason (there's not many good reasons to do it, but it's possible), then you might write SELECT * FROM grades WHERE "subject name" = 'latin' - "subject name" is the name of the column, 'latin' is a string.

Although double quotes are in the SQL standard, other DBMSes use different syntax for quoting identifiers, so may treat double quotes as an alternative for writing strings.

-- Postgres (also works in Microsoft SQL Server, but isn't the default style)
SELECT * FROM grades WHERE "subject name" = 'latin'
-- MySQL
SELECT * FROM grades WHERE `subject name` = 'latin'
-- Microsoft SQL Server
SELECT * FROM grades WHERE [subject name] = 'latin'

But if you always use single quotes for strings, and avoid names that need quoting, you'll run into fewer problems.

-- Works pretty much everywhere
SELECT * FROM grades WHERE subject = 'latin'


Related Topics



Leave a reply



Submit