【问题标题】:psql column doesn't exist but it doespsql 列不存在,但确实存在
【发布时间】:2018-10-05 00:49:52
【问题描述】:

我正在尝试从 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".

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

【问题讨论】:

  • 大写-交易日期与交易日期?
  • 我试过那个
  • 如果你不打电话给insider_app_ownershipdocument.transactionDate 只是transactiondate 会发生什么?

标签: sql postgresql


【解决方案1】:

(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;

【讨论】:

  • 您的意思是在创建表时,他们将列名放在引号中("transactionDate"),这迫使他们现在每次都在列名上使用引号?我是否正确理解了这一点?如果是这样,他们可能更愿意将该列重命名为 transactiondate
  • 不,不完全是。如果您选择了区分大小写的名称,则必须始终引用该名称。这不是很舒服,所以我会避免区分大小写的名称。但这是一个品味问题。
猜你喜欢
  • 2018-12-05
  • 2017-05-26
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 2015-09-25
  • 2018-05-15
相关资源
最近更新 更多