postgresqlでは、オブジェクト(テーブル名、カラム名)の名称はすべて小文字にすること#
- DB内には、大文字・小文字で区別して登録される
- SQL内では、"(ダブルクォーテーション)で囲まれているとそのままの文字列だが、囲まれていないと小文字に変換される(らしい)
- 結果、アンマッチが起きる
testdb=> \d iris
Table "public.iris"
Column | Type | Modifiers
---------------+-----------------------+-----------
Id | integer | not null
SepalLengthCm | numeric(15,2) |
SepalWidthCm | numeric(15,2) |
PetalLengthCm | numeric(15,2) |
PetalWidthCm | numeric(15,2) |
Species | character varying(20) |
Indexes:
"iris_pkey" PRIMARY KEY, btree ("Id")
testdb=> select * from iris where SepalLengthCm > 5.0; --<--- NG
ERROR: 列"sepallengthcm"は存在しません
LINE 1: select * from iris where SepalLengthCm > 5.0;
^
HINT: Perhaps you meant to reference the column "iris.SepalLengthCm".
testdb=> select * from iris where "iris.SepalLengthCm" > 5.0; --<--- NG
ERROR: 列"iris.SepalLengthCm"は存在しません
LINE 1: select * from iris where "iris.SepalLengthCm" > 5.0;
^
testdb=> select * from iris where "SepalLengthCm" > 5.0; --<--- OK
testdb=> select * from iris where iris."SepalLengthCm" > 5.0; --<--- OK
my previous blog post#
https://pumpkinpie-tea.blogspot.com/2016/06/postgresql.html