Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

php - 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"?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...