首页 > 解决方案 > psql 列不存在,但确实存在

问题描述

我正在尝试从 psql 命令行使用 postgresql 数据库中的原始 SQL 在我的数据表中选择单个列。我收到一条错误消息,指出该列不存在。然后它提示我使用我在 select 语句中引用的确切列。这是查询:

SELECT insider_app_ownershipdocument.transactionDate FROM insider_app_ownershipdocument;

这是错误消息:

ERROR:  column insider_app_ownershipdocument.transactiondate does not exist
SELECT insider_app_ownershipdocument.transactionDate FROM in...
HINT:  Perhaps you meant to reference the column "insider_app_ownershipdocument.transactionDate".

我不知道为什么这不起作用。

标签: sqlpostgresql

解决方案


(Postgres) SQL 会自动将名称转换为小写,尽管它支持区分大小写的名称。所以

SELECT insider_app_ownershipdocument.transactionDate FROM insider_app_ownershipdocument;

将相当于:

SELECT insider_app_ownershipdocument.transactiondate FROM insider_app_ownershipdocument;

您应该用双引号保护列名以避免这种影响:

SELECT insider_app_ownershipdocument."transactionDate" FROM insider_app_ownershipdocument;

推荐阅读