ラベル postgresql の投稿を表示しています。 すべての投稿を表示
ラベル postgresql の投稿を表示しています。 すべての投稿を表示

2016/06/26

オブジェクトの名称はすべて小文字にしておくこと - Postgresql

"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; -> ダメ
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;->ダメ
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

testdb=> 

雑多な1行コマンド&SQLメモ - Postgresql

メモ for Postgresql

‐Postgresql編




2016/06/25

Virtualbox上のUbuntu16.4にPostgresql 9.5をインストールする

MACのVirtualbox上のUbuntu16.4にPostgresql9.5をインストールする。
以下のSTEPをサーバー上で行う。(SSHでも可能)
#1# インストール
#2# Postgresqlを開始する
#3# postgresの初期パスワードを設定する
#4# postgres でログインして、DB作成と別userでもログインできるようにする

#5# クライアントからの接続を許可する


## pg_hba.confのセッティングについては、以下参考
-postgresqlのページ
https://www.postgresql.jp/document/9.5/html/auth-pg-hba-conf.html