Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Postgresql Statement - column name does not exists

I've been pulling my hair out. I have a very simple postgre database, one specific table has a column named lName (uppercase N). Now I know with postgre I must quote lName since it contains an uppercase N.

I am trying to query the database with the following statement:

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

But I am receive this error:

Warning: pg_query() [function.pg-query]: Query failed: ERROR: column "Smith" does not exist in .....

What is the issue here? Why is it saying the column is "Smith"?

like image 524
meenxo Avatar asked Apr 27 '11 06:04

meenxo


People also ask

Where column does not exist Postgres?

PostgreSQL column does not exist exception occurs when we have used column did not exist in the table or it will occur when the used column name has lower case name and we have used upper case in our query.

Does not exist in PostgreSQL?

The NOT EXISTS is opposite to EXISTS . It means that if the subquery returns no row, the NOT EXISTS returns true. If the subquery returns one or more rows, the NOT EXISTS returns false.

How do you add column if not exists PostgreSQL?

The Postgres IF NOT EXISTS syntaxFirst, we specify the name of the table to which we want to add a column. We supply the IF NOT EXISTS option after the ADD COLUMN clause, and then we specify the name of the column and its data type.


1 Answers

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?

like image 100
Marc Gravell Avatar answered Oct 26 '22 03:10

Marc Gravell