Simple Postgresql Statement - column name does not exists

前端 未结 2 1120
一向
一向 2020-11-27 23:31

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

相关标签:
2条回答
  • 2020-11-28 00:11

    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?

    0 讨论(0)
  • 2020-11-28 00:13

    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.

    0 讨论(0)
提交回复
热议问题