简单的 Postgresql 语句 - 列名不存在 [英] Simple Postgresql Statement - column name does not exists
问题描述
我一直在拔头发.我有一个非常简单的 postgre 数据库,一个特定的表有一个名为 lName(大写 N)的列.现在我知道使用 postgre 我必须引用 lName 因为它包含一个大写的 N.
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"
但我收到此错误:
警告:pg_query()[function.pg-query]:查询失败:错误:史密斯"列不存在在……
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"?
推荐答案
我猜:
SELECT * FROM employee WHERE "lName" LIKE 'Smith'
(注意不同的引号;"foo"
是带引号的标识符;'foo'
是字符串文字)
(note the different quotes; "foo"
is a quoted identifier; 'foo'
is a string literal)
此外,在大多数 SQL 方言中,没有通配符的 LIKE
等价于 =
;您的意思是要包含通配符吗?
Also, in most SQL dialects, a LIKE
without a wildcard is equivalent to =
; did you mean to include a wildcard?
这篇关于简单的 Postgresql 语句 - 列名不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!