gpt4 book ai didi

sql - PostgreSQL "Column does not exist"但实际上确实如此

转载 作者:行者123 更新时间:2023-11-29 11:16:54 24 4
gpt4 key购买 nike

我正在编写一个 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

如何才能成功运行查询?

最佳答案

尝试将其放入双引号中 - 如查询中的 "Continent":

SELECT "Continent"
FROM network.countries
...

关于sql - PostgreSQL "Column does not exist"但实际上确实如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41591386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com