Bul*_*aza 9 sql postgresql quoted-identifier
我正在编写一个Java自动构建和运行SQL查询的应用程序.对于许多表我的代码工作正常,但在某个表上它会因抛出以下异常而卡住:
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column "continent" does not exist
Hint: Perhaps you meant to reference the column "countries.Continent".
Position: 8
Run Code Online (Sandbox Code Playgroud)
已运行的查询如下:
SELECT Continent
FROM network.countries
WHERE Continent IS NOT NULL
AND Continent <> ''
LIMIT 5
Run Code Online (Sandbox Code Playgroud)
这实质上5从列中返回非空值.
我不明白为什么我在pgAdmin 4中明显地出现"列不存在"错误.我可以看到有一个名称Network包含表的模式countries,该表有一个名称Continent与预期一样的列.
由于应用程序本身检索了所有列,模式和表名称,我认为没有拼写或语义错误,为什么PostgreSQL会导致问题呢?在pgAdmin4中运行查询也不使用建议countries.Continent的工作.
我的PostgreSQL版本是迄今为止的最新版本:
$ psql --version
psql (PostgreSQL) 9.6.1
Run Code Online (Sandbox Code Playgroud)
如何成功运行查询?
Eug*_*sky 16
尝试将其变为双引号 - 就像"Continent"在查询中一样:
SELECT "Continent"
FROM network.countries
...
Run Code Online (Sandbox Code Playgroud)
在使用 SQLAlchemy 环境时,我遇到了这样的 SQL 错误,
db.session.execute(
text('SELECT name,type,ST_Area(geom) FROM buildings WHERE type == "plaza" '))
Run Code Online (Sandbox Code Playgroud)
错误:“广场”列不存在
好吧,我将 == 更改为 = ,错误仍然存在,然后我交换了引号,如下所示。有效。诡异的!
....
text("SELECT name,type,ST_Area(geom) FROM buildings WHERE type = 'plaza' "))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32530 次 |
| 最近记录: |