我正在编写一个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
已运行的查询如下:
SELECT Continent
FROM network.countries
WHERE Continent IS NOT NULL
AND Continent <> ''
LIMIT 5
这实际上5
从列中返回非空值。
我不明白为什么在pgAdmin 4中明显出现“列不存在”错误。我可以看到有一个名称Network
包含表的模式,countries
并且该表有一个Continent
按预期命名的列。
由于所有列、模式和表名都是由应用程序本身检索的,我认为没有拼写或语义错误,那么为什么PostgreSQL会导致问题呢?在 pgAdmin4 中运行查询也不使用建议countries.Continent
的工作。
我的 PostgreSQL 版本是目前最新的:
$ psql --version
psql (PostgreSQL) 9.6.1
如何成功运行查询?