【发布时间】:2019-05-29 12:52:30
【问题描述】:
所以我遇到了以下令我惊讶的行为。我首先认为 DateTime 可能是 postgres 数据类型,但 BidOpen 呢?然后是错误消息中列名的情况很有趣。我几乎觉得这与不区分大小写的未引用名称有关。 为什么我需要用引号将列名括起来才能使查询起作用?
mydatabase=# select max("DateTime") from fx.candle;
max
---------------------
2019-04-26 20:59:00
(1 row)
mydatabase=# select max(DateTime) from fx.candle;
ERROR: column "datetime" does not exist
LINE 1: select max(DateTime) from fx.candle;
^
HINT: Perhaps you meant to reference the column "candle.DateTime".
mydatabase=# select max(BidOpen) from fx.candle;
ERROR: column "bidopen" does not exist
LINE 1: select max(BidOpen) from fx.candle;
^
HINT: Perhaps you meant to reference the column "candle.BidOpen".
mydatabase=# select max("BidOpen") from fx.candle;
max
---------
125.816
(1 row)
架构如下所示:
mydatabase=# \d fx.candle;
Table "fx.candle"
Column | Type | Modifiers
-----------+-----------------------------+-----------------------------------------------------------------
id | integer | not null default nextval('fx.candle_id_seq'::regclass)
DateTime | timestamp without time zone |
BidOpen | double precision | not null
BidHigh | double precision | not null
BidLow | double precision | not null
BidClose | double precision | not null
AskOpen | double precision | not null
AskHigh | double precision | not null
AskLow | double precision | not null
AskClose | double precision | not null
symbol_id | integer |
Indexes:
"candle_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"candle_symbol_id_fkey" FOREIGN KEY (symbol_id) REFERENCES fx.symbol(id)
【问题讨论】:
-
试试:
select max(symbol_id) from fx.candle。你得到了什么? -
我认为这与 postgres 在不引用名称时不区分大小写有关,而列的名称是大小写。
标签: sql postgresql quoted-identifier