添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Because "Smith" is an identifier, and in that position, an identifier is expected to be a column. What you probably meant is a string literal, which uses single quotes: 'Smith'. So

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

You probably also want a wildcard in the string to search for ('Smith%'?). LIKE matching is anchored to the beginning and end of a string, unlike typical regular expression matching.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.