3
自己紹介 ( こんなの作ってた)
SELECT data, data + ' 拾 ' FROM ksj_sample;
data | ?column?
------------+----------------
五百壱拾六 | 五百弐拾六
零 | 壱拾
参万壱百壱 | 参万壱百壱拾壱
(3 rows)
SELECT data, data * ' 拾 ' FROM ksj_sample;
data | ?column?
------------+--------------
五百壱拾六 | 五千壱百六拾
零 | 零
参万壱百壱 | 参拾壱千壱拾
(3 rows)
SELECT sum(data) FROM ksj_sample;
sum
----------------
参万六百壱拾七
(1 row)
SELECT * FROM ksj_sample ORDER BY data;
data
------------
零
五百壱拾六
参万壱百壱
(3 rows)
ksj (漢数字型)
漢数字で四則演算や
比較演算できる、誰得データ型
4.
4
自己紹介 ( こんなの作ってた)
SELECT * FROM foo WHERE data = ' エバンゲリオン ';
id | data
----+------------
3 | エヴァンゲリヲン
(1 row)
SELECT * FROM foo WHERE data = ' センヌリティウス ';
id | data
----+------
(0 rows)
SELECT * FROM foo WHERE data /= ' センヌリティウス ';
id | data
----+------------------
4 | セリヌンティウス
(1 row)
ntext( ゆるい文字型 )
日本語正規化
ゆるい演算子 (/=)
類似度計算で typo を許容
5.
5
自己紹介 ( こんなの作ってた)
CREATE FOREIGN TABLE bar3 (
my_name text,
my_gender text,
follower_name text,
follower_gender text)
SERVER foo
OPTIONS (query '{
"query":"START n=node(*)
MATCH p=fm<-[]-n<-[]-fm
RETURN n.name as my_name, n.gender as my_gender,
fm.name as follower_name, fm.gender as follower_gender" }');
SELECT my_name, my_gender, follower_name, follower_gender FROM bar3;
my_name | my_gender | follower_name | follower_gender
---------+-----------+---------------+-----------------
Akagi | Famale | Hiryu | Famale
Nagato | Male | Mutsu | Male
Mutsu | Male | Nagato | Male
Hiryu | Famale | Soryu | Famale
Hiryu | Famale | Akagi | Famale
Soryu | Famale | Hiryu | Famale
(6 rows)
new4j_fdw
グラフデータベース Neo4j を
わざわざ PostgreSQL 経由で
SQL 検索する誰得 FDW
neo4j_fdw
6.
6
自己紹介 ( こんなの作ってた)
postgres=# LISTEN HB_CL;
LISTEN
postgres=# NOTIFY HB_SV,'xxxx';;
NOTIFY
Asynchronous notification "hb_cl" with payload "Invalid data.(xxxx)"
received from server process with PID 29520.
postgres=# NOTIFY HB_SV,'0123';;
NOTIFY
Asynchronous notification "hb_cl" with payload "2 Hit / 1 Blow."
received from server process with PID 29520.
postgres=# NOTIFY HB_SV,'0813';;
NOTIFY
Asynchronous notification "hb_cl" with payload "4 Hit! Conguratulatoins!, next new game."
received from server process with PID 29520.
postgres=#
hb_worker
psql などから数当てができる
Background Worker Process
29
hstore 型の使用例
hstore 型カラムを持つテーブル
other=#dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------
+--------------------------------------------------
hstore | 1.3 | public | data type for storing sets of (key, value)
pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
other=# d hstore_t
Table "public.hstore_t"
Column | Type | Modifiers
--------+---------+-------------------------------------------------------
id | integer | not null default nextval('hstore_t_id_seq'::regclass)
data | hstore |
43
パスによる値の取り出し
person, name, firstのパスで取得
jsonb=# SELECT '{"person":{"name":
{"first":"Tom","last":"Lane"},"age":59}}'::json #>> '{person, name,
first}';
?column?
----------
Tom
(1 row)
person
name
first last
age
Tom Lane
59
(root)
84
各キーから値を取得する btree インデックス群を設定
インデックスサイズ
JSONB列自体に GIN インデックスを設定
CREATE INDEX jsonb_id_idx ON jsonb_t
USING btree ((data->>'Id'));
CREATE INDEX jsonb_fullname_idx ON jsonb_t
USING btree ((data->>'Full Name'));
CREATE INDEX jsonb_email_idx ON jsonb_t
USING btree ((data->>'Email'));
CREATE INDEX jsonb_created_idx ON jsonb_t
USING btree ((data->>'Created At'));
CREATE INDEX jsonb_country_idx ON jsonb_t
USING btree ((data->>'Country'));
CREATE INDEX jsonb_data_idx ON jsonb_t USING gin (data jsonb_ops);