PostgreSQL“列不存在"但实际上 [英] PostgreSQL "Column does not exist" but it actually does

查看:569
本文介绍了PostgreSQL“列不存在"但实际上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Java应用程序以自动生成并运行SQL查询.对于许多表,我的代码工作正常,但在某些表上会抛出以下异常而卡住:

I'm writing a Java application to automatically build and run SQL queries. For many tables my code works fine but on a certain table it gets stuck by throwing the following exception:

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个非空值.

This essentially returns 5 non-empty values from the column.

我不明白为什么

I don't understand why I'm getting the "column does not exist" error when it clearly does in pgAdmin 4. I can see that there is a schema with the name Network which contains the table countries and that table has a column called Continent just as expected.

由于所有列,模式和表名均由应用程序本身检索,因此我不认为存在拼写或语义错误,为什么 PostgreSQL 会导致问题吗?在pgAdmin4中运行查询或使用建议的countries.Continent都有效.

Since all column, schema and table names are retrieved by the application itself I don't think there has been a spelling or semantical error so why does PostgreSQL cause problems regardless? Running the query in pgAdmin4 nor using the suggested countries.Continent is working.

到目前为止,我的PostgreSQL版本是最新的:

My PostgreSQL version is the newest as of now:

$ psql --version
psql (PostgreSQL) 9.6.1

如何成功运行查询?

推荐答案

尝试将其用双引号引起来-例如查询中的"Continent":

Try to take it into double quotes - like "Continent" in the query:

SELECT "Continent"
FROM network.countries
...

这篇关于PostgreSQL“列不存在"但实际上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆