sql - 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".
我不知道为什么这不起作用。
解决方案
(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;
推荐阅读
- python - 如果某些值为空,如何在 SUM 中返回空?
- vue.js - 如何在 Vuejs 中创建动态模型?
- android - 具有换行符的 BulletSpan 在 Android 中不起作用
- c# - 如何使用 Emgu CV、C# 将 256 色图像转换为 16 色图像?
- django - 如何通过django中的按钮删除记录
- python - 编写一个函数lines(a),确定将销毁多少个球
- java - 如何在休息调用的 post 方法中接受特殊字符和空格?
- php - 根据产品类别自动设置 WooCommerce 产品运输类别
- .net-core - 多个 api 版本的单个客户端
- python-3.x - 如何从python3中的unicode字符串打印一个真正的中文字符串?