Scott Siu!!! Postgres! 2016!! EnterpriseDB! RedHat RHCA! Who am I! (WeChat)!

Similar documents
學 科 100% ( 為 單 複 選 題, 每 題 2.5 分, 共 100 分 ) 1. 請 參 閱 附 圖 作 答 : (A) 選 項 A (B) 選 項 B (C) 選 項 C (D) 選 項 D Ans:D 2. 下 列 對 於 資 料 庫 正 規 化 (Normalization) 的 敘

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

目錄

vi JSON JSON API XML JSON JSON JavaScript RESTful JSON Douglas Crockford JSON / RESTful API JavaScript Node.js Ruby on Rails Java Groovy

1-1 database columnrow record field 不 DBMS Access Paradox SQL Server Linux MySQL Oracle IBM Informix IBM DB2 Sybase 1-2

目錄 C ontents Chapter MTA Chapter Chapter

ebook 165-5

基于ECO的UML模型驱动的数据库应用开发1.doc

0SQL SQL SQL SQL SQL 3 SQL DBMS Oracle DBMS DBMS DBMS DBMS RDBMS R DBMS 2 DBMS RDBMS R SQL SQL SQL SQL SELECT au_fname,au_ lname FROM authors ORDER BY

Oracle Database 10g: SQL (OCE) 的第一堂課

Process Data flow Data store External entity 6-10 Context diagram Level 0 diagram Level 1 diagram Level 2 diagram

<4D F736F F D20B1A6BCA6CAD0C7F8D3F2CEC0C9FAD0C5CFA2C6BDCCA8BBA5C1AABBA5CDA8CAB5CAA9B9E6B7B6>

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

epub 94-3

投影片 1

Chn 116 Neh.d.01.nis

基于UML建模的管理管理信息系统项目案例导航——VB篇

LEETCODE leetcode.com 一 个 在 线 编 程 网 站, 收 集 了 IT 公 司 的 面 试 题, 包 括 算 法, 数 据 库 和 shell 算 法 题 支 持 多 种 语 言, 包 括 C, C++, Java, Python 等 2015 年 3 月 份 加 入 了 R

Microsoft Word - (web)_F.1_Notes_&_Application_Form(Chi)(non-SPCCPS)_16-17.doc


What You Can Find with SciFinder Scholar SciFinder Scholar Area Information Available in SciFinder Scholar Document Title Information Author/inventor

软件测试(TA07)第一学期考试

Windows XP

ebook45-5

A API Application Programming Interface 见 应 用 程 序 编 程 接 口 ARP Address Resolution Protocol 地 址 解 析 协 议 为 IP 地 址 到 对 应 的 硬 件 地 址 之 间 提 供 动 态 映 射 阿 里 云 内

final

( Version 0.4 ) 1

KDC-U5049 KDC-U4049 Made for ipod, and Made for iphone mean that an electronic accessory has been designed to connect specifically to ipod, or iphone,

f2.eps

Microsoft Word - template.doc

untitled

PowerPoint Presentation

Logitech Wireless Combo MK45 English

JCR... 3 JCR... 3 ISI Web of Knowledge... 4 Cross Search... 5 Cross Search... 5 Cross Search ISI Web of Knowledge WOS... 8 Externa

ebook46-23

2015 Chinese FL Written examination

姓 名 : 蘇 海 彬 班 別 :1B 書 名 : 咆 哮 山 莊 作 者 : 今 次 我 想 介 紹 的 書 是 一 本 文 學 巨 著, 名 叫 咆 哮 山 莊 像 我 這 些 學 生 未 來 要 面 對 競 爭 很 強 勁 的 社 會, 然 而 可 從 一 些 文 學 名 著 來 從 少 學

(Geographic data or geodata ) 30 (Buelher, K and L. Mckee1996) (Open GIS Consortium OGC) OGC GIS Open GIS OGC (Geography Markup Langu

摘 要 在 這 忙 碌 的 社 會 中, 普 遍 人 們 運 動 時 間 其 實 並 不 充 裕, 體 力 越 來 越 差 的 情 況 下 還 隨 意 飲 食 導 致 身 體 健 康 越 來 越 差, 因 此 本 專 題 打 算 利 用 健 康 飲 食 的 方 式 改 善 這 些 人 的 體 質,

RunPC2_.doc

声 明 本 人 郑 重 声 明 : 此 处 所 提 交 的 硕 士 学 位 论 文 基 于 等 级 工 鉴 定 的 远 程 考 试 系 统 客 户 端 开 发 与 实 现, 是 本 人 在 中 国 科 学 技 术 大 学 攻 读 硕 士 学 位 期 间, 在 导 师 指 导 下 进 行 的 研 究

2 SGML, XML Document Traditional WYSIWYG Document Content Presentation Content Presentation Structure Structure? XML/SGML 3 2 SGML SGML Standard Gener

Microsoft Word - Functional_Notes_3.90_CN.doc

蔡 氏 族 譜 序 2

EJB-Programming-4-cn.doc

Preface This guide is intended to standardize the use of the WeChat brand and ensure the brand's integrity and consistency. The guide applies to all d

untitled

Microsoft Word 電腦軟體設計.doc

國家圖書館典藏電子全文

59 1 CSpace 2 CSpace CSpace URL CSpace 1 CSpace URL 2 Lucene 3 ID 4 ID Web 1. 2 CSpace LireSolr 3 LireSolr 3 Web LireSolr ID

「人名權威檔」資料庫欄位建置表

untitled

XML/DTD (1) XML (Markup) SGML HTML XML XML XML 2004/7/ All Rights Reserved 2

ENGG1410-F Tutorial 6

ebook 185-6

coverage2.ppt

2/80 2

DB2 (join) SQL DB2 11 SQL DB2 SQL 9.1 DB2 DB2 ( ) SQL ( ) DB2 SQL DB2 DB2 SQL DB2 DB2 SQL DB2 ( DB2 ) DB2 DB2 DB2 SQL DB2 (1) SQL (2) S

Oracle高级复制配置手册_业务广告_.doc

Oracle 4

通过Hive将数据写入到ElasticSearch

封面.PDF

ebook215-5

Microsoft PowerPoint - NCBA_Cattlemens_College_Darrh_B

天津天狮学院关于修订2014级本科培养方案的指导意见

CH01.indd

Microsoft Office SharePoint Server MOSS Web SharePoint Web SharePoint 22 Web SharePoint Web Web SharePoint Web Web f Lists.asmx Web Web CAML f

RUN_PC連載_12_.doc

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

A9RF716.tmp

创业板投资风险提示:本次股票发行后拟在创业板市场上市,该市场具有较高的投资风险

untitled

untitled

Microsoft Word htm

FileMaker 16 ODBC 和 JDBC 指南

目 錄 壹 青 輔 會 結 案 附 件 貳 活 動 計 劃 書 參 執 行 內 容 一 教 學 內 容 二 與 當 地 教 師 教 學 交 流 三 服 務 執 行 進 度 肆 執 行 成 效 一 教 學 課 程 二 與 當 地 教 師 教 學 交 流 三 服 務 滿 意 度 調 查 伍 服 務 檢

Microsoft Word - 100碩士口試流程

Microsoft Word - SupplyIT manual 3_cn_david.doc

untitled

软件概述

VB控件教程大全

ebook 96-16

科学计算的语言-FORTRAN95

FAQ -PowerDesigner9.5.DOC

Fuzzy Highlight.ppt


untitled

Chapter 9: Objects and Classes

1 目 錄 1. 簡 介 一 般 甄 試 程 序 第 一 階 段 的 準 備 第 二 階 段 的 準 備 每 間 學 校 的 面 試 方 式 各 程 序 我 的 做 法 心 得 及 筆 記 結 論..

在 ongodb 中实现强事务

untitled

4. 每 组 学 生 将 写 有 习 语 和 含 义 的 两 组 卡 片 分 别 洗 牌, 将 顺 序 打 乱, 然 后 将 两 组 卡 片 反 面 朝 上 置 于 课 桌 上 5. 学 生 依 次 从 两 组 卡 片 中 各 抽 取 一 张, 展 示 给 小 组 成 员, 并 大 声 朗 读 卡

「電子檔案統一命名原則之研究」計畫


回滚段探究

untitled

2 response personnel to speed up the rescue operations after various natural or man-made disasters. Keywords: SMS, Database, Disaster

RUN_PC連載_8_.doc

Transcription:

NOSQL in Postgres! play with MongoDB! scott.siu@postgres.cn!

Scott Siu!!! Postgres! 2016!! EnterpriseDB! RedHat RHCA! Who am I! (WeChat)!

提 纲 JSON 的背景 要 NoSQL 也要 ACID Postgres: JSON in SQL Play with MongoDB

JSON 的背景 JSON(JavaScript Object Notation) 是一种轻量级的数据 交换格式 易于人阅读和编写 同时也易于机器解析和生成 它基于 JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999 的一个子集 JSON 采用完全独立于语言的文本格式, 但是也使用了类似于 C 语言家族的习惯 ( 包括 C, C++, C#, Java, JavaScript, Perl, Python 等 ) 这些特性使 JSON 成为理想的数据交换语言 JSON 已经是 JavaScript 标准的一部分 目前, 主流的浏览器对 JSON 支持都非常完善 应用 JSON, 我们可以从 XML 的解析中摆脱出来, 对那些应用 Ajax 的 Web 2.0 网站来说,JSON 确实是目前最灵活的轻量级方案

JSON 的背景 <book>! XML! <type>textbook</type>! <pages>256</pages>! <title>programming Pearls 2nd Edition</title>! <description>the first edition of Programming Pearls was one of the most influential books I read early in my career...</ description>! <rating>4.5</rating>! <covertype>paperback</covertype>! <genre>computer Science</genre>! <author>jon Bentley</author>! <publisher>addison-wesley Professional</publisher>! <copyright>1999</copyright>! </book>!

JSON 的背景 {! JSON! "book": {! "type": "textbook",! "pages": "256",! "title": "Programming Pearls 2nd Edition",! "description": "The first edition of Programming Pearls was one of the most influential books I read early in my career...",! "rating": "4.5",! "covertype": "paperback",! "genre": "Computer Science",! "author": "Jon Bentley",! "publisher": "Addison-Wesley Professional",! "copyright": "1999"! }! }!

JSON 的背景 使用上面的 XML 和 JSON 文件分别运行解析测试 10,000,000 次 结果并不令人惊讶, 解析和转换 JSON 成一个 Java 对象的速度比 XML 解析速度提高了 30%, 占用空间少 30% 这些结果似乎和多数开发社区对两种格式的看法一样 所以, 换用 JSON 处理数据在性能上可以有不小的提升, 而且还 会减少空间的占用

要 NoSQL 与要 ACID 传统用户数据场景 RDBMS - 关系型数据库 应用系统 格式各异的 同类数据 格式化 统一的 数据模型

要 NoSQL 与要 ACID 灵活存储各种格式 应用定义数据类型 大表, 大字段 可拆可合 移动互联网新数据场景 NoSQL 非关系型数据库

要 NoSQL 与要 ACID 传统用户数据场景 强一致性 分段进行 规范统一 移动互联网数据场景 灵活构建 整体存储 分段展现 左边 Insert, 右边 save 左边 Select, 右边 find 码农就是 996 终生无缘 007

Postgres: JSON in SQL HSTORE Key-value pair Simple, fast and easy Postgres v 8.2 pre-dates many NoSQL-only solutions Ideal for flat data structures that are sparsely populated JSON Hierarchical document model Introduced in Postgres 9.2, perfected in 9.3 JSONB Binary version of JSON Faster, more operators and even more robust Postgres 9.4

Postgres: JSON in SQL Creating a table with a JSONB field CREATE TABLE json_data (data JSONB); Simple JSON data element: {"name": "Apple Phone", "type": "phone", "brand":"acme", "price": 200, "available": true, "warranty_years": 1} Inserting this data element into the table json_data INSERT INTO json_data (data) VALUES (' {"name": "Apple Phone", "type": "phone", "brand": "ACME", "price": 200, "available": true, "warranty_years": 1} ')

Postgres: JSON in SQL 支持嵌套 数组 : { full name : John Joseph Carl Salinger, names : [ {"type": "firstname", value : John }, { type : middlename, value : Joseph }, { type : middlename, value : Carl }, { type : lastname, value : Salinger } ] }

Postgres: JSON in SQL SELECT DISTINCT data->>'name' as products FROM json_data; products ------------------------------ Cable TV Basic Service Package AC3 Case Black Phone Service Basic Plan AC3 Phone AC3 Case Green Phone Service Family Plan 注意 : 这里返回的不是 JSON 格式的数据, 而是返回普通的字符串类型数据, 传统应用可以直接读取进行展示

Postgres: JSON in SQL SELECT data FROM json_data; data ------------------------------------------ {"name": "Apple Phone", "type": "phone", "brand": "ACME", "price": 200,"available": true, "warranty_years": 1} 注意 : 这里返回的是 JSON 格式的字符串类型, 可以直接通过如 Node.js 等进行直接读取, 解析并展示到页面上

Postgres: JSON in SQL 1. Number: Signed decimal number that may contain a fractional part and may use exponential notation. No distinction between integer and floating-point 2. String A sequence of zero or more Unicode characters. Strings are delimited with double-quotation mark Supports a backslash escaping syntax. 3. Boolean Either of the values true or false.

Postgres: JSON in SQL 4. Array An ordered list of zero or more values, Each values may be of any type. Arrays use square bracket notation with elements being comma-separated. 5. Object An unordered associative array (name/value pairs). Objects are delimited with curly brackets Commas to separate each pair Each pair the colon ':' character separates the key or name from its value. All keys must be strings and should be distinct from each other within that object. 6. null An empty value, using the word null

Postgres: JSON in SQL { "firstname": "John", -- String Type "lastname": "Smith", -- String Type "isalive": true, -- Boolean Type "age": 25, -- Number Type "height_cm": 167.6, -- Number Type "address": { -- Object Type "streetaddress": "21 2nd Street, "city": "New York, "state": "NY, "postalcode": "10021-3100 }, "phonenumbers": [ // Object Array { "type": "home, "number": "212 555-1234 }, // Object { "type": "office, "number": "646 555-4567 } ], "children": [], "spouse": null }

Postgres: JSON in SQL CREATE TABLE json_data (data jsonb); INSERT INTO json_data VALUES ('{"name":"xxx","brand":"aaa", "available":true}');

Postgres: JSON in SQL JSONB 数据类型 Canonical representation Whitespace and punctuation dissolved away Only one value per object key is kept Last insert wins Key order determined by length, then bytewise comparison Equality, containment and key/element presence tests Smaller, faster GIN indexes jsonb subdocument indexes Use get operators to construct expression indexes on subdocument: CREATE INDEX author_index ON books USING GIN ((jsondata -> 'authors')); SELECT * FROM books WHERE jsondata -> 'authors'? 'Carl Bernstein'

Postgres: JSON in SQL

Play with MongoDB

Play with MongoDB CREATE EXTENSION mongo_fdw; CREATE SERVER mongo_server FOREIGN DATA WRAPPER mongo_fdw OPTIONS (address '172.24.39.129', port '27017'); CREATE USER MAPPING FOR postgresql SERVER mongo_server OPTIONS (username 'mongo', password 'mongo'); CREATE FOREIGN TABLE mongo_data( name text, brand text, type text) SERVER mongo_server OPTIONS ( database 'benchmark', collection 'json_tables');

Play with MongoDB SELECT * FROM mongo_data WHERE brand='acme' limit 10; name brand type -------------+-------+------- AC7553 Phone ACME phone AC7551 Phone ACME phone AC7519 Phone ACME phone AC7565 Phone ACME phone AC7555 Phone ACME phone AC7529 Phone ACME phone AC7528 Phone ACME phone AC7547 Phone ACME phone AC7587 Phone ACME phone AC7541 Phone ACME phone (10 rows)

Play with MongoDB INSERT INTO mongo_data(name, brand, type) VALUES('iphone6 phone','apple Inc','phone'); SELECT* FROM mongo_data WHERE brand='apple Inc'; _id name brand type --------------------------+----------------+-----------+------- 53ea4f59fe5586a15714881d iphone6 phone Apple Inc phone UPDATE mongo_data SET brand='apple Product' WHERE brand='apple Inc ; SELECT * FROM mongo_data WHERE brand='apple Product ; _id name brand type --------------------------+----------------+---------------+------- 53ea4f59fe5586a15714881d iphone6 phone Apple Product phone

PostgreSQL! - Not Only SQL(NOSQL) -!

(WeChat)!! Q & A!