Kouhei Sutou
null+****@clear*****
Fri Jun 9 00:54:31 JST 2017
Kouhei Sutou 2017-06-09 00:54:31 +0900 (Fri, 09 Jun 2017) New Revision: 6891769b644cf61b6ac17e37ae7da2ad5caee3b3 https://github.com/pgroonga/pgroonga.github.io/commit/6891769b644cf61b6ac17e37ae7da2ad5caee3b3 Message: script-jsonb: translate Added files: _po/ja/reference/operators/script-jsonb-v2.po ja/reference/operators/script-jsonb-v2.md Modified files: ja/reference/operators/contain-jsonb.md reference/operators/script-jsonb-v2.md Added: _po/ja/reference/operators/script-jsonb-v2.po (+454 -0) 100644 =================================================================== --- /dev/null +++ _po/ja/reference/operators/script-jsonb-v2.po 2017-06-09 00:54:31 +0900 (e6beadf) @@ -0,0 +1,454 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"PO-Revision-Date: 2017-06-09 00:52+0900\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +msgid "" +"---\n" +"title: \"&` operator for jsonb type\"\n" +"upper_level: ../\n" +"---" +msgstr "" +"---\n" +"title: \"jsonb型用の&`演算子\"\n" +"upper_level: ../\n" +"---" + +msgid "# `` &`` `` operator for `jsonb` type" +msgstr "# `jsonb`型用の`` &`` ``演算子" + +msgid "Since 1.2.1." +msgstr "1.2.1で追加。" + +msgid "## Summary" +msgstr "## 概要" + +msgid "" +"`` &` `` operator is a PGroonga original operator. You can use complex conditi" +"on that can't be written by [`@>` operator][contain-jsonb] such as range searc" +"h." +msgstr "" +"`` &` ``演算子はPGroonga独自の演算子です。[`@>`演算子][contain-jsonb]では書けない範囲検索のような複雑な条件を書くことが" +"できます。" + +msgid "" +"If you know [JsQuery][jsquery], you can understand like \"PGroonga provides `js" +"onb` type related search features that are similar to JsQuery with different s" +"yntax\"." +msgstr "" +"もし[JsQuery][jsquery]を知っているなら、「PGroongaはJsQueryが提供しているような`jsonb`型用の検索機能を違う構文で提供" +"している」と理解してください。" + +msgid "## Syntax" +msgstr "## 構文" + +msgid "Here is the syntax of this operator:" +msgstr "この演算子の構文は次の通りです。" + +msgid "" +"```sql\n" +"jsonb_column &` condition\n" +"```" +msgstr "" + +msgid "`jsonb_column` is a column that its type is `jsonb`." +msgstr "`jsonb_column`は`jsonb`型のカラムです。" + +msgid "" +"`condition` is a `text` value used as query. It uses [Groonga's script syntax]" +"[groonga-script-syntax]." +msgstr "" +"`condition`はクエリーとして使う`text`型の値です。[Groongaのスクリプト構文][groonga-script-syntax]を使います" +"。" + +msgid "" +"The operator returns `true` when `condition` matches `jsonb_column` value, `fa" +"lse` otherwise." +msgstr "この演算子は`condition`が`jsonb_column`の値にマッチしたら`true`を返し、マッチしなかったら`false`を返します。" + +msgid "## Operator classes" +msgstr "## 演算子クラス" + +msgid "" +"You need to specify one of the following operator classes to use this operator" +":" +msgstr "この演算子を使うには次のどれかの演算子クラスを指定する必要があります。" + +msgid " * `pgroonga.jsonb_ops`: Default for `jsonb`" +msgstr " * `pgroonga.jsonb_ops`:`jsonb`型のデフォルト" + +msgid " * `pgroonga.jsonb_ops_v2`: For `jsonb`" +msgstr " * `pgroonga.jsonb_ops_v2`:`jsonb`型用" + +msgid "## Usage" +msgstr "## 使い方" + +msgid "Here are sample schema and data for examples:" +msgstr "例に使うサンプルスキーマとデータは次の通りです。" + +msgid "" +"```sql\n" +"CREATE TABLE logs (\n" +" record jsonb\n" +");" +msgstr "" + +msgid "CREATE INDEX pgroonga_logs_index ON logs USING pgroonga (record);" +msgstr "" + +msgid "" +"INSERT INTO logs\n" +" VALUES ('{\n" +" \"message\": \"Server is started.\",\n" +" \"host\": \"www.example.com\",\n" +" \"tags\": [\n" +" \"web\",\n" +" \"example.com\"\n" +" ]\n" +" }');\n" +"INSERT INTO logs\n" +" VALUES ('{\n" +" \"message\": \"GET /\",\n" +" \"host\": \"www.example.com\",\n" +" \"code\": 200,\n" +" \"tags\": [\n" +" \"web\",\n" +" \"example.com\"\n" +" ]\n" +" }');\n" +"INSERT INTO logs\n" +" VALUES ('{\n" +" \"message\": \"Send to <info �� example.com>.\",\n" +" \"host\": \"mail.example.net\",\n" +" \"tags\": [\n" +" \"mail\",\n" +" \"example.net\"\n" +" ]\n" +" }');\n" +"```" +msgstr "" + +msgid "Disable sequential scan:" +msgstr "シーケンシャルスキャンを無効にします。" + +msgid "" +"```sql\n" +"SET enable_seqscan = off;\n" +"```" +msgstr "" + +msgid "" +"You need to understand how PGroonga creates index against `jsonb` type value t" +"o create search condition." +msgstr "検索条件を作るためにはPGroongaが`jsonb`型のデータ用のインデックスをどのように作るかを理解する必要があります。" + +msgid "" +"PGroonga splits a `jsonb` type value into values and then creates indexes agai" +"nst these values. In SQL, think about the following schema:" +msgstr "" +"PGroongaは`jsonb`型の値を複数の値に分割し、それらの分割した値に対してインデックスを作成します。SQLで言うと次のスキーマを作っていると考えて" +"ください。" + +msgid "" +"```sql\n" +"CREATE TABLE values (\n" +" key text PRIMARY KEY,\n" +" path text,\n" +" paths text[],\n" +" type text,\n" +" boolean boolean,\n" +" number double precision,\n" +" string text,\n" +" size numeric\n" +");\n" +"```" +msgstr "" + +msgid "Here are descriptions of column:" +msgstr "各カラムの説明は次の通りです。" + +msgid "" +" * `key`: The ID of the value. If value has the same path and content, `key` " +"is the same value. Key format is `'${PATH}|${TYPE}|${VALUE}'`. It's not used i" +"n search condition." +msgstr "" +" * `key`:値のIDです。値が違うパスで違う内容なら`key`は違う値になります。キーのフォーマットは`'${パス}|${種類}|${値}'`です。" +"このカラムは検索条件には使いません。" + +msgid "" +" * `path`: The path of the value from root. It uses [jq][jq] compatible forma" +"t. Object is `[\"${ELEMENT_NAME}\"]`, array is `[]`. For example, the path of `\"" +"web\"` in `{\"tags\": [\"web\"]}` is `.[\"tags\"][]`. If you know absolute path of th" +"e value, you can use this value in search condition." +msgstr "" +" * `path`:値がある位置へのルートからのパスです。[jq][jq]互換のフォーマットです。オブジェクトは`[\"${要素名}\"]`で配列は`[]`で" +"す。たとえば、`{\"tags\": [\"web\"]}`の中の`\"web\"`のパスは`.[\"tags\"][]`です。もし、値の絶対パスを知っているなら検索条件で" +"この値を使えます。" + +msgid "" +" * `paths`: The paths of the value. It includes absolute path, sub paths, `.$" +"{ELEMENT_NAME1}.${ELEMENT_NAME2}` format paths and paths without array. This c" +"olumn is convenient for search condition because you can use one of them for s" +"earch condition. Here are paths for `\"x\"` in `{\"a\": {\"b\": \"c\": [\"x\"]}}`:" +msgstr "" +" * `paths`: 値を示すパスです。値を示すパスは複数あります。絶対パス、サブパス、`.${要素名1}.${要素名2}`というフォーマットのパス、配" +"列部分を省略したパスがあります。このカラムは検索条件の指定を便利にするために用意されています。検索時にはこの中のパスのどれでも使うことができます。以下はどれ" +"も`{\"a\": {\"b\": \"c\": [\"x\"]}}`の中の`\"x\"`を指定するパスです。" + +msgid "" +" * `.a.b.c`\n" +" * `.[\"a\"][\"b\"][\"c\"]`\n" +" * `.[\"a\"][\"b\"][\"c\"][]`\n" +" * `a.b.c`\n" +" * `[\"a\"][\"b\"][\"c\"]`\n" +" * `[\"a\"][\"b\"][\"c\"][]`\n" +" * `b.c`\n" +" * `[\"b\"][\"c\"]`\n" +" * `[\"b\"][\"c\"][]`\n" +" * `c`\n" +" * `[\"c\"]`\n" +" * `[\"c\"][]`\n" +" * `[]`" +msgstr "" + +msgid " * `type`: The type of the value. This column value is one of them:" +msgstr " * `type`:値の種類です。このカラムの値は次のどれかになります。" + +msgid " * `\"object\"`: Object. No value." +msgstr " * `\"object\"`:オブジェクト。値はありません。" + +msgid " * `\"array\"`: Array. The number of elements is stored in `size` column." +msgstr " * `\"array\"`:配列。`size`カラムに要素数が入っています。" + +msgid " * `\"boolean\"`: Boolean. The value is stored in `boolean` column." +msgstr " * `\"boolean\"`:真偽値。`boolean`カラムに値が入っています。" + +msgid " * `\"number\"`: Number. The value is stored in `number` column." +msgstr " * `\"number\"`:数値。`number`カラムに値が入っています。" + +msgid " * `\"string\"`: String. The value is stored in `string` column." +msgstr " * `\"string\"`:文字列。`string`カラムに値が入っています。" + +msgid "" +" * `boolean`: The value if `type` column value is `\"boolean\"`, `false` otherw" +"ise." +msgstr " * `boolean`:`type`カラムの値が`\"boolean\"`なら値が入っています。それ以外のときは`false`が入っています。" + +msgid " * `number`: The value if `type` column value is `\"number\"`, `0` otherwise." +msgstr " * `number`:`type`カラムの値が`\"number\"`なら値が入っています。それ以外のときは`0`が入っています。" + +msgid " * `string`: The value if `type` column value is `\"string\"`, `\"\"` otherwise." +msgstr " * `string`:`type`カラムの値が`\"string\"`なら値が入っています。それ以外のときは`\"\"`が入っています。" + +msgid "" +" * `size`: The number of elements if `type` column value is `\"array\"`, `0` ot" +"herwise." +msgstr " * `size`:`type`カラムの値が`\"array\"`なら要素数が入っています。それ以外のときは`0`が入っています。" + +msgid "Here is a sample JSON:" +msgstr "以下はサンプルJSONです。" + +msgid "" +"```json\n" +"{\n" +" \"message\": \"GET /\",\n" +" \"host\": \"www.example.com\",\n" +" \"code\": 200,\n" +" \"tags\": [\n" +" \"web\",\n" +" \"example.com\"\n" +" ]\n" +"}\n" +"```" +msgstr "" + +msgid "" +"The JSON is split to the following values. (They are part of all split values." +")" +msgstr "このJSONを次の値に分割します。(これは分割した値の一部です。)" + +msgid "" +"| key | path | paths | type | boolean | number | string | size |\n" +"| --- | ---- | ----- | ---- | ------- | ------ | ------ | ---- |\n" +"| `.|object` | `.` | `[.]` | `object` | | | | |\n" +"| `.[\"message\"]|string|GET /` | `.[\"message\"]` | `[.message, .[\"message\"], mes" +"sage, [\"message\"]]` | `string` | | | `GET /` | |\n" +"| `.[\"tags\"][]|string|web` | `.[\"tags\"]` | `[.tags, .[\"tags\"], .[\"tags\"][], ta" +"gs, [\"tags\"], [\"tags\"][], []]` | `string` | | | `web` | |" +msgstr "" + +msgid "" +"You specify condition that matches split value to `` &` `` operator. If there " +"is one or more split values that match specified condition in `jsonb` type val" +"ue, the `jsonb` type value is matched." +msgstr "" +"`` &` ``演算子を使って、分割した値にマッチする条件を指定します。もし、`jsonb`型の値の中に条件にマッチする分割した値が1つ以上ある場合はその`" +"jsonb`型の値はマッチしたことになります。" + +msgid "" +"Here is a condition that searches `jsonb` type value that has `www.example.com" +"` string:" +msgstr "次は`www.example.com`という文字列値を含む`jsonb`型の値を検索する条件です。" + +msgid "" +"(It uses [`jsonb_pretty()` function][postgresql-jsonb-pretty] provided since P" +"ostgreSQL 9.5 for readability.)" +msgstr "" +"(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数][postgresql-jsonb-pretty]を使" +"っています。)" + +msgid "" +"```sql\n" +"SELECT jsonb_pretty(record) FROM logs WHERE record &` 'string == \"www.example." +"com\"';\n" +"-- jsonb_pretty \n" +"-- -------------------------------------\n" +"-- { +\n" +"-- \"host\": \"www.example.com\", +\n" +"-- \"tags\": [ +\n" +"-- \"web\", +\n" +"-- \"example.com\" +\n" +"-- ], +\n" +"-- \"message\": \"Server is started.\"+\n" +"-- }\n" +"-- { +\n" +"-- \"code\": 200, +\n" +"-- \"host\": \"www.example.com\", +\n" +"-- \"tags\": [ +\n" +"-- \"web\", +\n" +"-- \"example.com\" +\n" +"-- ], +\n" +"-- \"message\": \"GET /\" +\n" +"-- }\n" +"-- (2 rows)\n" +"```" +msgstr "" + +msgid "" +"Here is a condition that searches `jsonb` type value that has number between `" +"200` to `299` as `code` column value. The condition uses `paths @ \"...\"` synta" +"x to use simple path format (`.code`) to specify path." +msgstr "" +"以下は`code`カラムの値として`200`から`299`の間の数値を持っている`jsonb`型の値を検索する条件です。この条件はパスの指定に簡易パスフォー" +"マット(`.code`)を使うため、`paths @ \"...\"`という構文を使っています。" + +msgid "" +"```sql\n" +"SELECT jsonb_pretty(record) FROM logs WHERE record &` 'paths @ \".code\" && numb" +"er >= 200 && number < 300';\n" +"-- jsonb_pretty \n" +"-- --------------------------------\n" +"-- { +\n" +"-- \"code\": 200, +\n" +"-- \"host\": \"www.example.com\",+\n" +"-- \"tags\": [ +\n" +"-- \"web\", +\n" +"-- \"example.com\" +\n" +"-- ], +\n" +"-- \"message\": \"GET /\" +\n" +"-- }\n" +"-- (1 row)\n" +"```" +msgstr "" + +msgid "" +"Here is a condition for full text search from all text values in `jsonb` value" +" type:" +msgstr "`jsonb`型の値の中のすべてのテキスト値に対して全文検索をする条件は次の通りです。" + +msgid "" +"```sql\n" +"SELECT jsonb_pretty(record) FROM logs WHERE record &` 'string @ \"started\"';\n" +"-- jsonb_pretty \n" +"-- -------------------------------------\n" +"-- { +\n" +"-- \"host\": \"www.example.com\", +\n" +"-- \"tags\": [ +\n" +"-- \"web\", +\n" +"-- \"example.com\" +\n" +"-- ], +\n" +"-- \"message\": \"Server is started.\"+\n" +"-- }\n" +"-- (1 row)\n" +"```" +msgstr "" + +msgid "" +"You can use [Groonga's query syntax][groonga-query-syntax] (`a OR b` can be us" +"ed) for full text search by `query(\"string\", \"...\")` syntax:" +msgstr "" +"全文検索用に[Groongaのクエリー構文][groonga-query-syntax](`a OR b`という構文を使えます)を使うには`query(\"s" +"tring\", \"...\")`という構文を使います。\n" + +msgid "" +"```sql\n" +"SELECT jsonb_pretty(record) FROM logs WHERE record &` 'query(\"string\", \"send O" +"R server\")';\n" +"-- jsonb_pretty \n" +"-- ----------------------------------------------\n" +"-- { +\n" +"-- \"host\": \"www.example.com\", +\n" +"-- \"tags\": [ +\n" +"-- \"web\", +\n" +"-- \"example.com\" +\n" +"-- ], +\n" +"-- \"message\": \"Server is started.\" +\n" +"-- }\n" +"-- { +\n" +"-- \"host\": \"mail.example.net\", +\n" +"-- \"tags\": [ +\n" +"-- \"mail\", +\n" +"-- \"example.net\" +\n" +"-- ], +\n" +"-- \"message\": \"Send to <info �� example.com>.\"+\n" +"-- }\n" +"-- (2 rows)\n" +"```" +msgstr "" + +msgid "## See also" +msgstr "## 参考" + +msgid " * [`jsonb` support][jsonb]" +msgstr " * [`jsonb`サポート][jsonb]" + +msgid " * [`@>` operator][contain-jsonb]: Search by a `jsonb` data" +msgstr " * [`@>`演算子][contain-jsonb]:`jsonb`データを使った検索" + +msgid "[jsonb]:../jsonb.html" +msgstr "" + +msgid "[contain-jsonb]:contain-jsonb.html" +msgstr "" + +msgid "[jsquery]:https://github.com/postgrespro/jsquery" +msgstr "" + +msgid "[jq]:https://stedolan.github.io/jq/" +msgstr "" + +msgid "" +"[groonga-query-syntax]:http://groonga.org/docs/reference/grn_expr/query_syntax" +".html" +msgstr "" +"[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/query_syn" +"tax.html" + +msgid "" +"[groonga-script-syntax]:http://groonga.org/docs/reference/grn_expr/script_synt" +"ax.html" +msgstr "" +"[groonga-script-syntax]:http://groonga.org/ja/docs/reference/grn_expr/script_s" +"yntax.html" + +msgid "" +"[postgresql-jsonb-pretty]:{{ site.postgresql_doc_base_url.en }}/functions-json" +".html#FUNCTIONS-JSON-PROCESSING-TABLE" +msgstr "" +"[postgresql-jsonb-pretty]:{{ site.postgresql_doc_base_url.ja }}/functions-json" +".html#FUNCTIONS-JSON-PROCESSING-TABLE" Modified: ja/reference/operators/contain-jsonb.md (+30 -8) =================================================================== --- ja/reference/operators/contain-jsonb.md 2017-06-09 00:38:09 +0900 (b11952e) +++ ja/reference/operators/contain-jsonb.md 2017-06-09 00:54:31 +0900 (9234b97) @@ -9,21 +9,30 @@ upper_level: ../ PGroongaは`@>`演算子の検索をインデックスを使って高速に実現できます。 -[`@>`演算子はPostgreSQL組み込みの演算子]({{ site.postgresql_doc_base_url.ja }}/functions-json.html#functions-jsonb-op-table)です。`@>`演算子は右辺の`jsonb`型の値が左辺の`jsonb`型の値のサブセットなら真を返します。 +[`@>`演算子はPostgreSQL組み込みの演算子][postgresql-jsonb-operators]です。`@>`演算子は右辺の`jsonb`型の値が左辺の`jsonb`型の値のサブセットなら真を返します。 + ## 構文 この演算子の構文は次の通りです。 ```sql -jsonb_column @> jsonb_query +column @> query ``` -`jsonb_column`は`jsonb`型のカラムです。 +`column`は検索対象のカラムです。型は`jsonb`型です。 + +`query`はクエリーに使う`jsonb`型の値です。 + +この演算子は`query`が`column`の値のサブセットなら`true`を返し、それ以外の時は`false`を返します。 -`jsonb_query`はクエリーとして使う`jsonb`型の値です。 +## 演算子クラス -この演算子は`jsonb_query`が`jsonb_column`の値のサブセットなら`true`を返し、そうでない場合は`false`を返します。 +この演算子を使うには次のどれかの演算子クラスを指定する必要があります。 + + * `pgroonga.jsonb_ops`:`jsonb`型のデフォルト + + * `pgroonga.jsonb_ops_v2`:`jsonb`型用 ## 使い方 @@ -74,7 +83,7 @@ SET enable_seqscan = off; マッチする例は次の通りです。 -(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数]({{ site.postgresql_doc_base_url.ja }}/functions-json.html#functions-json-processing-table)を使っています。) +(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数][postgresql-jsonb-pretty]を使っています。) ```sql SELECT jsonb_pretty(record) FROM logs WHERE record @> '{"host": "www.example.com"}'::jsonb; @@ -115,5 +124,18 @@ SELECT jsonb_pretty(record) FROM logs WHERE record @> '{"tags": ["mail", "web"]} ## 参考 - * [`jsonb`サポート](../jsonb.html) - * [`@@`演算子](jsonb-query.html) + * [`jsonb`サポート][jsonb] + + * [`&?`演算子][query-jsonb-v2]:`jsonb`内のすべてのテキストデータを便利なクエリー言語を使った全文検索 + + * [`` &` ``演算子][script-jsonb-v2]:ECMAScriptのようなクエリー言語を使った高度な検索 + +[jsonb]:../jsonb.html + +[query-jsonb-v2]:query-jsonb-v2.html + +[script-jsonb-v2]:script-jsonb-v2.html + +[postgresql-jsonb-operators]:{{ site.postgresql_doc_base_url.ja }}/functions-json.html#FUNCTIONS-JSONB-OP-TABLE + +[postgresql-jsonb-pretty]:{{ site.postgresql_doc_base_url.ja }}/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE Added: ja/reference/operators/script-jsonb-v2.md (+275 -0) 100644 =================================================================== --- /dev/null +++ ja/reference/operators/script-jsonb-v2.md 2017-06-09 00:54:31 +0900 (5c06f7a) @@ -0,0 +1,275 @@ +--- +title: "jsonb型用の&`演算子" +upper_level: ../ +--- + +# `jsonb`型用の`` &`` ``演算子 + +1.2.1で追加。 + +## 概要 + +`` &` ``演算子はPGroonga独自の演算子です。[`@>`演算子][contain-jsonb]では書けない範囲検索のような複雑な条件を書くことができます。 + +もし[JsQuery][jsquery]を知っているなら、「PGroongaはJsQueryが提供しているような`jsonb`型用の検索機能を違う構文で提供している」と理解してください。 + +## 構文 + +この演算子の構文は次の通りです。 + +```sql +jsonb_column &` condition +``` + +`jsonb_column`は`jsonb`型のカラムです。 + +`condition`はクエリーとして使う`text`型の値です。[Groongaのスクリプト構文][groonga-script-syntax]を使います。 + +この演算子は`condition`が`jsonb_column`の値にマッチしたら`true`を返し、マッチしなかったら`false`を返します。 + +## 演算子クラス + +この演算子を使うには次のどれかの演算子クラスを指定する必要があります。 + + * `pgroonga.jsonb_ops`:`jsonb`型のデフォルト + + * `pgroonga.jsonb_ops_v2`:`jsonb`型用 + +## 使い方 + +例に使うサンプルスキーマとデータは次の通りです。 + +```sql +CREATE TABLE logs ( + record jsonb +); + +CREATE INDEX pgroonga_logs_index ON logs USING pgroonga (record); + +INSERT INTO logs + VALUES ('{ + "message": "Server is started.", + "host": "www.example.com", + "tags": [ + "web", + "example.com" + ] + }'); +INSERT INTO logs + VALUES ('{ + "message": "GET /", + "host": "www.example.com", + "code": 200, + "tags": [ + "web", + "example.com" + ] + }'); +INSERT INTO logs + VALUES ('{ + "message": "Send to <info �� example.com>.", + "host": "mail.example.net", + "tags": [ + "mail", + "example.net" + ] + }'); +``` + +シーケンシャルスキャンを無効にします。 + +```sql +SET enable_seqscan = off; +``` + +検索条件を作るためにはPGroongaが`jsonb`型のデータ用のインデックスをどのように作るかを理解する必要があります。 + +PGroongaは`jsonb`型の値を複数の値に分割し、それらの分割した値に対してインデックスを作成します。SQLで言うと次のスキーマを作っていると考えてください。 + +```sql +CREATE TABLE values ( + key text PRIMARY KEY, + path text, + paths text[], + type text, + boolean boolean, + number double precision, + string text, + size numeric +); +``` + +各カラムの説明は次の通りです。 + + * `key`:値のIDです。値が違うパスで違う内容なら`key`は違う値になります。キーのフォーマットは`'${パス}|${種類}|${値}'`です。このカラムは検索条件には使いません。 + + * `path`:値がある位置へのルートからのパスです。[jq][jq]互換のフォーマットです。オブジェクトは`["${要素名}"]`で配列は`[]`です。たとえば、`{"tags": ["web"]}`の中の`"web"`のパスは`.["tags"][]`です。もし、値の絶対パスを知っているなら検索条件でこの値を使えます。 + + * `paths`: 値を示すパスです。値を示すパスは複数あります。絶対パス、サブパス、`.${要素名1}.${要素名2}`というフォーマットのパス、配列部分を省略したパスがあります。このカラムは検索条件の指定を便利にするために用意されています。検索時にはこの中のパスのどれでも使うことができます。以下はどれも`{"a": {"b": "c": ["x"]}}`の中の`"x"`を指定するパスです。 + + * `.a.b.c` + * `.["a"]["b"]["c"]` + * `.["a"]["b"]["c"][]` + * `a.b.c` + * `["a"]["b"]["c"]` + * `["a"]["b"]["c"][]` + * `b.c` + * `["b"]["c"]` + * `["b"]["c"][]` + * `c` + * `["c"]` + * `["c"][]` + * `[]` + + * `type`:値の種類です。このカラムの値は次のどれかになります。 + + * `"object"`:オブジェクト。値はありません。 + + * `"array"`:配列。`size`カラムに要素数が入っています。 + + * `"boolean"`:真偽値。`boolean`カラムに値が入っています。 + + * `"number"`:数値。`number`カラムに値が入っています。 + + * `"string"`:文字列。`string`カラムに値が入っています。 + + * `boolean`:`type`カラムの値が`"boolean"`なら値が入っています。それ以外のときは`false`が入っています。 + + * `number`:`type`カラムの値が`"number"`なら値が入っています。それ以外のときは`0`が入っています。 + + * `string`:`type`カラムの値が`"string"`なら値が入っています。それ以外のときは`""`が入っています。 + + * `size`:`type`カラムの値が`"array"`なら要素数が入っています。それ以外のときは`0`が入っています。 + +以下はサンプルJSONです。 + +```json +{ + "message": "GET /", + "host": "www.example.com", + "code": 200, + "tags": [ + "web", + "example.com" + ] +} +``` + +このJSONを次の値に分割します。(これは分割した値の一部です。) + +| key | path | paths | type | boolean | number | string | size | +| --- | ---- | ----- | ---- | ------- | ------ | ------ | ---- | +| `.|object` | `.` | `[.]` | `object` | | | | | +| `.["message"]|string|GET /` | `.["message"]` | `[.message, .["message"], message, ["message"]]` | `string` | | | `GET /` | | +| `.["tags"][]|string|web` | `.["tags"]` | `[.tags, .["tags"], .["tags"][], tags, ["tags"], ["tags"][], []]` | `string` | | | `web` | | + +`` &` ``演算子を使って、分割した値にマッチする条件を指定します。もし、`jsonb`型の値の中に条件にマッチする分割した値が1つ以上ある場合はその`jsonb`型の値はマッチしたことになります。 + +次は`www.example.com`という文字列値を含む`jsonb`型の値を検索する条件です。 + +(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数][postgresql-jsonb-pretty]を使っています。) + +```sql +SELECT jsonb_pretty(record) FROM logs WHERE record &` 'string == "www.example.com"'; +-- jsonb_pretty +-- ------------------------------------- +-- { + +-- "host": "www.example.com", + +-- "tags": [ + +-- "web", + +-- "example.com" + +-- ], + +-- "message": "Server is started."+ +-- } +-- { + +-- "code": 200, + +-- "host": "www.example.com", + +-- "tags": [ + +-- "web", + +-- "example.com" + +-- ], + +-- "message": "GET /" + +-- } +-- (2 rows) +``` + +以下は`code`カラムの値として`200`から`299`の間の数値を持っている`jsonb`型の値を検索する条件です。この条件はパスの指定に簡易パスフォーマット(`.code`)を使うため、`paths @ "..."`という構文を使っています。 + +```sql +SELECT jsonb_pretty(record) FROM logs WHERE record &` 'paths @ ".code" && number >= 200 && number < 300'; +-- jsonb_pretty +-- -------------------------------- +-- { + +-- "code": 200, + +-- "host": "www.example.com",+ +-- "tags": [ + +-- "web", + +-- "example.com" + +-- ], + +-- "message": "GET /" + +-- } +-- (1 row) +``` + +`jsonb`型の値の中のすべてのテキスト値に対して全文検索をする条件は次の通りです。 + +```sql +SELECT jsonb_pretty(record) FROM logs WHERE record &` 'string @ "started"'; +-- jsonb_pretty +-- ------------------------------------- +-- { + +-- "host": "www.example.com", + +-- "tags": [ + +-- "web", + +-- "example.com" + +-- ], + +-- "message": "Server is started."+ +-- } +-- (1 row) +``` + +全文検索用に[Groongaのクエリー構文][groonga-query-syntax](`a OR b`という構文を使えます)を使うには`query("string", "...")`という構文を使います。 + + +```sql +SELECT jsonb_pretty(record) FROM logs WHERE record &` 'query("string", "send OR server")'; +-- jsonb_pretty +-- ---------------------------------------------- +-- { + +-- "host": "www.example.com", + +-- "tags": [ + +-- "web", + +-- "example.com" + +-- ], + +-- "message": "Server is started." + +-- } +-- { + +-- "host": "mail.example.net", + +-- "tags": [ + +-- "mail", + +-- "example.net" + +-- ], + +-- "message": "Send to <info �� example.com>."+ +-- } +-- (2 rows) +``` + +## 参考 + + * [`jsonb`サポート][jsonb] + + * [`@>`演算子][contain-jsonb]:`jsonb`データを使った検索 + +[jsonb]:../jsonb.html + +[contain-jsonb]:contain-jsonb.html + +[jsquery]:https://github.com/postgrespro/jsquery + +[jq]:https://stedolan.github.io/jq/ + +[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/query_syntax.html + +[groonga-script-syntax]:http://groonga.org/ja/docs/reference/grn_expr/script_syntax.html + +[postgresql-jsonb-pretty]:{{ site.postgresql_doc_base_url.ja }}/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE Modified: reference/operators/script-jsonb-v2.md (+1 -1) =================================================================== --- reference/operators/script-jsonb-v2.md 2017-06-09 00:38:09 +0900 (338a355) +++ reference/operators/script-jsonb-v2.md 2017-06-09 00:54:31 +0900 (947f5c9) @@ -257,7 +257,7 @@ SELECT jsonb_pretty(record) FROM logs WHERE record &` 'query("string", "send OR * [`jsonb` support][jsonb] - * [`@>` operator][contain-jsonb] + * [`@>` operator][contain-jsonb]: Search by a `jsonb` data [jsonb]:../jsonb.html -------------- next part -------------- HTML����������������������������...Download