by shigemk2

当面は技術的なことしか書かない

PostgreSQL

postgresql interval

date '2001-09-28' + interval '1 hour' interval '1' みたいな書き方だとNG https://www.postgresql.jp/document/7.2/user/functions-datetime.html

postgresql if

postgresqlにifはないっぽいのでcase whenなどを使う https://www.postgresql.jp/document/9.4/html/functions-conditional.html

concat string in PostgreSQL

別にconcatじゃなくてもよかった sqliteでもこんな感じの書き方。 select 'Post' || 'greSQL' || ' OK' https://www.postgresql.jp/document/9.3/html/functions-string.html

to_char

date_format的なアレはPostgreにはない SELECT to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH12:MI:SS'), to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') https://www.postgresql.jp/document/9.4/html/functions-formatting.html

postgresql 正規表現

正規表現 regexp_replaceはデフォルトでは最初のマッチだけを返すが、gフラグを最後につけることで全部を返す https://www.postgresql.jp/document/9.4/html/functions-matching.html

CREATE EXTENSION

CREATE EXTENSION 拡張のインストール pg_available_extensionsで確認可能 select * from pg_available_extensions https://www.postgresql.jp/document/9.2/html/sql-createextension.html

memo fuzzystrmatch

memo fuzzystrmatch 文字列間の類似度や相違度を決める複数の関数を提供するモジュール create extension fuzzystrmatch; を実行することで使えるようになる utf-8のようなマルチバイト符号化方式には十分に対応できない 全レコードから似ている文字列群をピ…

PostgreSQLのスキーマとsearch_path

スキーマはデータベースを「用途別に分割した単位」としてとらえる MySQLにはない考え方。データベースの中に、スキーマ。そして、PostgreSQLではユーザーはpublicスキーマに割り当てられる。割り当てられるので、set search_pathで別のスキーマに割り当てる…

psql

もろもろのコマンドたち。 https://www.postgresql.jp/document/9.2/html/app-psql.html

postgresqlのパスワードなど。

https://www.postgresql.jp/document/9.3/html/libpq-pgpass.html hostname:port:database:username:password そういえば、DBごとにパスワード設定出来るのね。 読み進めていけば良いのか。 https://www.postgresql.jp/document/9.3/html/index.html

コマンド一覧を適当に

基本的にバックスラッシュから始まるものが多め。 General \copyright show PostgreSQL usage and distribution terms \g [FILE] or ; execute query (and send results to file or |pipe) \gset [PREFIX] execute query and store results in psql variable…

homebrewでPostgreSQLインストール(Marvericks)

↓のやつをそのままなぞればMarvericksでもいけました。 Homebrewを使ったPostgreSQLのインストール(Mac OS Lion) - Qiita $ postgres -V ‹system› postgres (PostgreSQL) 9.3.3 インストール→DB初期化→PostgreSQLサーバ起動→DB一覧 brew install postgresql …