PostgreSQL 9.5.4 中的奇怪大小写转换

Strange case conversion in PostgreSQL 9.5.4

SELECT AVG(MY_AE_Actual) FROM MY_Data_Details

导致错误:

ERROR: column "my_ae_actual" does not exist LINE 1: SELECT AVG(MY_AE_Actual) FROM MY_Data_Details ^ HINT: Perhaps you meant to reference the column "my_data_details.my_ae_actual111". ********** Fehler **********

ERROR: column "my_ae_actual" does not exist SQL Status:42703 Hinweis:Perhaps you meant to reference the column "my_data_details.my_ae_actual111". Zeichen:12

更新

很奇怪。我现在在 PostgreSQL 10 中使用以下 table:

进行了测试
CREATE TABLE public.testable
(
    id integer NOT NULL DEFAULT nextval('testable_id_seq'::regclass),
    string_data1 character varying(255) COLLATE pg_catalog."default",
    "String_Data2" character varying(255) COLLATE pg_catalog."default",
    "string_Data3" character varying(255) COLLATE pg_catalog."default",
    "String_data4" character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT testable_pkey PRIMARY KEY (id)
)

select string_data1 from testable - 成功
select String_data1 from testable - 成功
select string_Data1 from testable - 成功
select String_Data1 from testable - 成功
select "string_data1" from testable - 成功
select "String_data1" from testable - 失败
select "string_Data1" from testable - 失败
select "String_Data1" from testable - 失败
select string_data2 from testable - 失败
select String_data2 from testable - 失败
select string_Data2 from testable - 失败
select String_Data2 from testable - 失败
select "string_data2" from testable - 失败
select "String_data2" from testable - 失败
select "string_Data2" from testable - 失败
select "String_Data2" from testable - 成功

事实证明,没有引号的 PostgreSQL 不是 "case insensitive",而是 "lower casing",这完全没有意义。

Postgresql 强制小写,除非你使用双引号所以

ThisFieldName == thisfieldname

但是:

"ThisFieldName"  <> ThisFieldName
"ThisFieldName"  <> thisfieldname

如果您像 "ThisFieldName" 一样创建您的字段,您需要同样地引用它。

在您的情况下,您尝试使用 MY_AE_Actual,但 postgresql 告诉您 my_ae_actual 名称不存在。

table 个名字也是如此。

我的建议是不要在 Postgresql 中使用大写字母。我使用所有带下划线 _ 的小写字母作为分隔符。但这只是个人喜好。