国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

PostgreSQL JSON

2019-11-09 13:32:03
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
PostgreSQL 9.3.4 Documentation
 
PRevUpChapter 9. Functions and OperatorsNext

9.15. JSON Functions and Operators

Table 9-39 shows the operators that are available for use with JSON (see Section 8.14) data.

Table 9-39. JSON Operators

OperatorRight Operand TypeDescriptionExample
->intGet JSON array element'[1,2,3]'::json->2
->textGet JSON object field'{"a":1,"b":2}'::json->'b'
->>intGet JSON array element as text'[1,2,3]'::json->>2
->>textGet JSON object field as text'{"a":1,"b":2}'::json->>'b'
#>array of textGet JSON object at specified path'{"a":[1,2,3],"b":[4,5,6]}'::json#>'{a,2}'
#>>array of textGet JSON object at specified path as text'{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'

Table 9-40 shows the functions that are available for creating and manipulating JSON (see Section 8.14) data.

Table 9-40. JSON Support Functions

FunctionReturn TypeDescriptionExampleExample Result
array_to_json(anyarray [, pretty_bool])jsonReturns the array as JSON. A PostgreSQL multidimensional array becomes a JSON array of arrays. Line feeds will be added between dimension 1 elements if pretty_bool is true.array_to_json('{{1,5},{99,100}}'::int[])[[1,5],[99,100]]
row_to_json(record [, pretty_bool])jsonReturns the row as JSON. Line feeds will be added between level 1 elements if pretty_bool is true.row_to_json(row(1,'foo')){"f1":1,"f2":"foo"}
to_json(anyelement)jsonReturns the value as JSON. If the data type is not built in, and there is a cast from the type to json, the cast function will be used to perform the conversion. Otherwise, for any value other than a number, a Boolean, or a null value, the text representation will be used, escaped and quoted so that it is legal JSON.to_json('Fred said "Hi."'::text)"Fred said /"Hi./""
json_array_length(json)intReturns the number of elements in the outermost JSON array.json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]')5
json_each(json)SETOF key text, value jsonExpands the outermost JSON object into a set of key/value pairs.select * from json_each('{"a":"foo", "b":"bar"}')
 key | value-----+------- a   | "foo" b   | "bar" 
json_each_text(from_json json)SETOF key text, value textExpands the outermost JSON object into a set of key/value pairs. The returned value will be of type text.select * from json_each_text('{"a":"foo", "b":"bar"}')
 key | value-----+------- a   | foo b   | bar 
json_extract_path(from_json json, VARIADIC path_elems text[])jsonReturns JSON object pointed to by path_elems.json_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4'){"f5":99,"f6":"foo"}
json_extract_path_text(from_json json, VARIADIC path_elems text[])textReturns JSON object pointed to by path_elems.json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4', 'f6')foo
json_object_keys(json)SETOF textReturns set of keys in the JSON object. Only the "outer" object will be displayed.json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}')
 json_object_keys------------------ f1 f2
json_populate_record(base anyelement, from_json json, [, use_json_as_text bool=false]anyelementExpands the object in from_json to a row whose columns match the record type defined by base. Conversion will be best effort; columns in base with no corresponding key in from_json will be left null. If a column is specified more than once, the last value is used.select * from json_populate_record(null::x, '{"a":1,"b":2}')
 a | b---+--- 1 | 2
json_populate_recordset(base anyelement, from_json json, [, use_json_as_text bool=false]SETOF anyelementExpands the outermost set of objects in from_json to a set whose columns match the record type defined by base. Conversion will be best effort; columns in base with no corresponding key in from_json will be left null. If a column is specified more than once, the last value is used.select * from json_populate_recordset(null::x, '[{"a":1,"b":2},{"a":3,"b":4}]')
 a | b---+--- 1 | 2 3 | 4 
json_array_elements(json)SETOF jsonExpands a JSON array to a set of JSON elements.json_array_elements('[1,true, [2,false]]')
   value----------- 1 true [2,false]

Note: The json functions and operators can impose stricter validity requirements than the type's input functions. In particular, they check much more closely that any use of Unicode surrogate pairs to designate characters outside the Unicode Basic Multilingual Plane is correct.

Note: Many of these functions and operators will convert Unicode escapes in the JSON text to the appropriate UTF8 character when the database encoding is UTF8. In other encodings the escape sequence must be for an ASCII character, and any other code point in a Unicode escape sequence will result in an error. In general, it is best to avoid mixing Unicode escapes in JSON with a non-UTF8 database encoding, if possible.

Note: The hstore extension has a cast from hstore to json, so that converted hstore values are represented as JSON objects, not as string values.

See also Section 9.20 about the aggregate function json_agg which aggregates record values as JSON efficiently.


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 伊吾县| 奉化市| 绥滨县| 唐海县| 那曲县| 福鼎市| 久治县| 镇远县| 平遥县| 昆山市| 雷州市| 芮城县| 建阳市| 建水县| 枣庄市| 六安市| 上虞市| 乐陵市| 阳原县| 金山区| 新邵县| 阿拉善右旗| 三江| 章丘市| 铜梁县| 金门县| 育儿| 昭通市| 靖州| 白银市| 凤山市| 霸州市| 永川市| 保康县| 姚安县| 翁牛特旗| 中牟县| 基隆市| 左云县| 合水县| 阳谷县|