diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/1.PostgreSQL\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/1.PostgreSQL\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4a4cfd9f3f3533b8cdd0a7b9cb7543bb7ee0f84a 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/1.PostgreSQL\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/1.PostgreSQL\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "server.md", + "notebook_enable": false, + "exercise_id": "88b033cd97c642ef9900e5e091e335ff" +} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/3.\344\275\277\347\224\250PostgreSQL/develop.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/3.\344\275\277\347\224\250PostgreSQL/develop.json" index 2a13c11a1b2ef810fdcf3b16d03324449c20ec8c..3d1103ce048927a2d65afdadd048540e7007e7cb 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/3.\344\275\277\347\224\250PostgreSQL/develop.json" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/3.\344\275\277\347\224\250PostgreSQL/develop.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "develop.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "257414ca11f24a35a6270166b6bd2830" } \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" deleted file mode 100644 index 561a89f282404214c2e80b2615f2ceddd0c83e4e..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "basic.md", - "notebook_enable": false -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" deleted file mode 100644 index 9d3b09c9474fa45ca8e771467d5a878b743f4a7a..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" +++ /dev/null @@ -1,43 +0,0 @@ -# 基本语法 - -下列 SQL 语句,哪一项不合法? - -## 答案 - -```postgresql -from test select abc; -``` - -## 选项 - - -### A - -```postgresql -select 3.14; -``` - -### B - -```postgresql -select * from employee; -``` - -### C - -```postgresql -select * from employee where dept = 'hr'; -``` - -### D - -```postgresql -select id, name, dept, salary from employee where salary > 10000::money; -``` - -### E - -```postgresql -select now(); -``` - diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" deleted file mode 100644 index 226c817f66f2bb58b646e1dabe17e16bd6c88abb..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-dca8da7637f94ded91a1871daa51746e", - "keywords": ["语法", "select"], - "children": [], - "export": ["basic.json"] -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/concept.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/concept.json" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/concept.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/concept.md" deleted file mode 100644 index 66f30a9343dccc012227c7044e7888661b966df0..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/concept.md" +++ /dev/null @@ -1,31 +0,0 @@ -# 基本概念 - -下列叙述中,正确的是 - -1. 带有 select 关键字的查询不会修改数据 -2. 查询表需要 select 权限 -3. 修改一个数据库表或对象的结构,通常语句中会出现 create、add、drop、alter 等关键字 -4. 修改数据内容,通常会出现update、insert、delete等关键字 -5. update、insert、delete可以单独授权 - -## 答案 - -2, 3, 4, 5 - -## 选项 - -### A - -1, 2, 3, 4, 5 - -### B - -4, 5 - -### C - -1, 2, 3 - -### D - -3, 4, 5 \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/config.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/config.json" deleted file mode 100644 index eff0052817986e37b26d08fef470adf94b76a6f9..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/config.json" +++ /dev/null @@ -1,11 +0,0 @@ -{ - "node_id": "pg-b0f366abe12e41b0a9672d317e556662", - "keywords": ["DML", "insert", "update", "delete"], - "children": [], - "export": [ - "insert.json", - "update.json", - "delete.json", - "concept.json" - ] -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.json" deleted file mode 100644 index 0d9b33f01824c9ef71aa2f0b0c54658fbafbf9eb..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "delete.md", - "notebook_enable": false, - "exercise_id": "78e6ca15ba794ef3b2092de4640308b9" -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.md" deleted file mode 100644 index 57f50db5d7288e926d8fb3883bbd90221a89325b..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/delete.md" +++ /dev/null @@ -1,89 +0,0 @@ -# 删除 - -SmartMarket 公司的业务数据库中,有一个 orders 表,其结构主要是以下形态: - -```postgresql -create table orders -( - id serial primary key, - meta jsonb default '{}'::jsonb, - content jsonb default '{}'::jsonb, - created_at timestamp default now(), - deal boolean -) -``` - -有一个业务系统会实时的将已经成交(deal 字段为 true)的订单数据转储,现在我们仅需要一个清理 程序,将已经成 交的数据从 orders 表删除并记录被删除的数据id。下面哪个操作是对的? - -## 答案 - -在一个独立的定时任务中执行 - -```postgresql -delete -from orders -where deal -returning id; -``` - -并记录id - -## 选项 - -### A - -在一个独立的定时任务中执行 - -```postgresql -truncate orders; -``` - -### B - -在一个独立的定时任务中执行 - -```postgresql -delete -from orders; -``` - -### C - -在一个独立的定时任务中执行 - -```postgresql -drop table orders; -create table orders -( - id serial primary key, - meta jsonb default '{}'::jsonb, - content jsonb default '{}'::jsonb, - created_at timestamp default now(), - deal boolean -); -``` - -### D - -建立视图 - -```postgresql -create view order_view as -select id, meta, content, created_at -from orders -where not deal; -``` - -并要求业务系统只能访问这个视图。 - -### E - -在一个独立的定时任务中执行 - -```postgresql -delete -from orders -where deal; -``` - -并记录操作前后表中的最大 id \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.json" deleted file mode 100644 index 9f3d239883717ce0f48abd10b8262662e39abb7e..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "insert.md", - "notebook_enable": false, - "exercise_id": "2d562e3ae4a84e648de31452a67ba71f" -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.md" deleted file mode 100644 index 60ea20f5d3abd384002c30460a24a4355b164de3..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/insert.md" +++ /dev/null @@ -1,55 +0,0 @@ -# 插入 - -现有一个表: - -```postgresql -create table book( - id serial primary key , - title text not null , - meta jsonb default '{}'::jsonb, - price money, - isbn text not null , - publish_at date not null -); -create unique index on book(isbn); -create index on book using gin(meta); -``` - -那么下列哪个选项的代码可以执行成功? - -## 答案 - -```postgresql -insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; -insert into book(title, price, isbn, publish_at) select 'a other book title', 25.4, 'yy-yyyy-xxxx', '2019-12-1'::date; -``` - -## 选项 - -### 唯一键冲突 - -```postgresql -insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; -insert into book(title, price, isbn, publish_at) select 'a other book title', 35.4, 'xx-xxxx-xxxx', '2019-12-1'::date; -``` - -### 缺少必要的列 - -```postgresql -insert into book(price, isbn, publish_at) select 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; -insert into book(price, isbn, publish_at) select 35.4, 'yy-yyyy-xxxx', '2019-12-1'::date; -``` - -### 类型错误 - -```postgresql -insert into book(title, price, isbn, publish_at) select 'a book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; -insert into book(title, price, isbn, publish_at) select 'a other book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; -``` - -### 违反非空约束 - -```postgresql -insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; -insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; -``` diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.json" deleted file mode 100644 index 3d5628ed786f0143539d426cfb2c402c0edeeebb..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "update.md", - "notebook_enable": false, - "exercise_id": "d6f2c270c3cd41a499715e55a2c565ba" -} \ No newline at end of file diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.md" deleted file mode 100644 index c4b998f04833a537decef6b71a152cd666991b96..0000000000000000000000000000000000000000 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\343\200\201DML\345\222\214DDL/update.md" +++ /dev/null @@ -1,49 +0,0 @@ -# 更新数据 - -现有 employee 表如下: - -```postgresql -create table employee -( - id serial primary key, - name text, - dept text, - salary money -); -``` - -我们希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其增加 1000,返回她的工号。正确的修改语句是: - -## 答案 - -```postgresql -update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk' returning id; -``` - -## 选项 - -### 过滤条件不严谨 - -```postgresql -update employee set salary = salary + 1000 where name = 'Dora Muk' returning id; -``` - -### 没有返回员工id - -```postgresql -update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk'; -``` - - -### 缺少过滤条件 - -```postgresql -update employee set salary = salary + 1000 returning id; -``` - -### 错误的赋值语句 - -```postgresql -update employee set salary += 1000 returning id; -``` - diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" index 9b14469b05c64a3a724233dcd5393cd717e71fd4..1e8e1153ebe6b6d275feb24821124f67e3b16a82 100644 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" +++ "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "subquery.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "82be2aa951304dc9869cd7177fcba99f" } \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" deleted file mode 100644 index 4158705eeb68bc8d607426b67357aa6e503ae6e1..0000000000000000000000000000000000000000 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-eb4048b7dfd3469f8049330ba78427b5", - "keywords": [], - "children": [], - "export": ["loop.json"] -} \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" deleted file mode 100644 index 2cdec7a77920404dd9858003d6b7e692ab4e2e7d..0000000000000000000000000000000000000000 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "loop.md", - "notebook_enable": false -} \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" deleted file mode 100644 index 83b52303dff3cc20de0d1f917a2aec1b30eec33d..0000000000000000000000000000000000000000 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" +++ /dev/null @@ -1,66 +0,0 @@ -# 循环 - -下面哪一项定义的函数可以生成指定范围内的整数数列? - -## 答案 - -```postgresql -create function gen(start integer, stop integer) returns setof integer as $$ -begin - for idx in start .. stop loop - return next idx; - end loop; -end; -$$ language plpgsql; -``` - -## 选项 - -### A - -```postgresql -create function gen(start integer, stop integer) returns integer as $$ -begin - for idx in start .. stop loop - return idx; - end loop; -end; -$$ language plpgsql; -``` - -### B - -```postgresql -create function gen(start integer, stop integer) returns integer as $$ -begin - for idx in start .. stop loop - yield idx; - end loop; -end; -$$ language plpgsql; -``` - -### C - -```postgresql -create function gen(start integer, stop integer) returns setof integer as $$ -begin - for idx in start .. stop loop - return idx; - idx += 1; - end loop; -end; -$$ language plpgsql; -``` - -### D - -```postgresql -create function gen(start integer, stop integer) returns setof integer as $$ -begin - for idx in start .. stop loop - select idx; - end loop ; -end; -$$ language plpgsql; -``` \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/8.DDL/config.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/8.DDL/config.json" deleted file mode 100644 index 0fc750a98ac0baa796dc77125b92260a3c1dbd85..0000000000000000000000000000000000000000 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/8.DDL/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-0378bcd60ccd4dfebcfead92abbdd673", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" deleted file mode 100644 index b99d8b54997bf034899150b1cce368a47da36d3a..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/config.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/config.json" deleted file mode 100644 index a53d11583eb90dd54559fd0896373565e0c8dd56..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-69ad784e39c044d7a115cfd124e49ef1", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.json" deleted file mode 100644 index 5ef2622a00282644015139dee5887ee560448162..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "code_options", - "author": "刘鑫", - "source": "json.md", - "notebook_enable": false -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.md" deleted file mode 100644 index f6daaf1ca691f186d9a39b7c660b328c8f6fae04..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/json.md" +++ /dev/null @@ -1,31 +0,0 @@ -# JSON 和 JSONB 类型 - -关于 JSON 和 JSONB 类型,哪句话是错的? - -## 答案 - -JSON 就是 文本类型的封装,JSONB 是 JSON 的二进制压缩格式,JSON 和 JSONB 的功能与 TEXT 类型一样。 - -## 选项 - -### A - -JSONB 是推荐的 JSON 字段类型,更为高效。 - -### B - -JSONB 可以通过 GIST 倒排索引优化对内部结构的查询。 - - -### C - -PostgreSQL JSON 和 JSONB 支持 JSON PATH表达式 - -### D - -JSONB 和 文本可以有效兼容 - -### E - -JSON 和 JSONB 与其它类型一样,不能部分修改,只能作为整体插入或更新 - diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/match.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/match.json" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/match.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/match.md" deleted file mode 100644 index a51534d433d9af72138b8e8f522a1f89f8d17cf9..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/match.md" +++ /dev/null @@ -1,56 +0,0 @@ -# 匹配 - -表 book 的 meta 有类似如下结构: - -```json -{ - "author": [ - "Mars Liu", - "Milly Lee" - ], - "ISBN": "xxxx-xxxx-xxxxxx", - "version": 1 -} -``` - -该字段有 gist 索引。 - -如果我们想高效率的找到所有作者包含 Jim Gray 的书,应该如何查询? - -## 答案 - -```postgresql -select * from book where meta @> '{"author": ["Jim Gray"]}'::jsonb; -``` - -## 选项 - -### A - -```postgresql -select * from book where meta @> '["Jim Gray"]'::jsonb; -``` - -### A - -```postgresql -select * from book where 'Jim Gray' in meta; -``` - -### B - -```postgresql -select * from book where meta::text like '%Jim Gray%'; -``` - -### C - -```postgresql -select * from book having meta @> 'Jim Gray' -``` - -### D - -```postgresql -select * from book where 'Jim Gray' in (meta #>> 'author'); -``` diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/tags.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/tags.json" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/tags.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/tags.md" deleted file mode 100644 index b15550792a7f463effc4fd4875b976e10650c575..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.JSON\345\222\214JSONB/tags.md" +++ /dev/null @@ -1,46 +0,0 @@ -# 标签 - -现有一个表 sku: - -```postgresql -create table sku( - id serial primary key , - name text, - meta jsonb default '{}'::jsonb, - tags jsonb default '[]'::jsonb -) -``` - -我们希望查找包含所有给定tag的商品,那么查询应该是: - -## 答案 - -```postgresql -select id, name, meta, tags from sku where tags @> $1; -``` - -## 选项 - -### A - -```postgresql -select id, name, meta, tags from sku where tags = $1; -``` - -### B - -```postgresql -select id, name, meta, tags from sku where tags::text = $1; -``` - -### C - -```postgresql -select id, name, meta, tags from sku where $1 in tags; -``` - -### D - -```postgresql -select id, name, meta, tags from sku where tags in $1; -``` diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/config.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/config.json" deleted file mode 100644 index 6268b0be48ff42b024e48ffe56d4845578c665f2..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-6dbbb44b41d347b58075a9155dfb8356", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/distinct.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/distinct.json" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/distinct.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/distinct.md" deleted file mode 100644 index 0e661f628f3ede3e4cfa8bc04c6631dcf87f0966..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\345\207\275\346\225\260/distinct.md" +++ /dev/null @@ -1,46 +0,0 @@ -# 去重 - -下列函数中,有一个实现了合并两个 jsonb 对象并对其去重,是哪一项? - -## 答案 - -```postgresql -create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as -$$ - select jsonb_agg(distinct (value)) from jsonb_array_elements(a || b) -$$ language sql -``` - -## 选项 - -### A - -```postgresql -create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as $$ - select a || b -$$ language sql -``` - -### B - -```postgresql -create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as $$ -return jsonb_agg(distinct(value)) from jsonb_array_elements(a||b) -$$ language sql -``` - -### C - -```postgresql -create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as $$ - return next jsonb_agg(distinct(value)) from jsonb_array_elements(a||b) -$$ language sql -``` - -### D - -```postgresql -create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as $$ - select a + b; -$$ language sql -``` \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/config.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/config.json" deleted file mode 100644 index 5c230df395d3d6b1344791637c0a74e015a3d337..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "pg-532f8f84ea74493a9581e6bf720ebf78", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/view.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/view.json" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/view.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/view.md" deleted file mode 100644 index 9d4c2f407b2fc568407dac67abc2f540c0f80700..0000000000000000000000000000000000000000 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/5.\350\247\206\345\233\276/view.md" +++ /dev/null @@ -1,30 +0,0 @@ -# 视图 - -SmartMarket 公司的数据分析师,每天要执行一个固定的复杂查询,生成每日报表。我们准备将其创建为视图,这能够解决: - -1. 简化查询 -2. 降低查询时死锁的风险 -3. 大幅优化查询性能 -4. 限制权限 - -## 答案 - -1, 4 - -## 选项 - -### A - -1. 2, 3, 4 - -### B - -1, 2, 3 - -### C - -2, 3 - -### D - -3, 4 \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.\351\200\217\350\247\206\350\241\250 /pivot.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.\351\200\217\350\247\206\350\241\250 /pivot.json" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..824979b9801b31371adee1b75e10c23b50dee42a 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.\351\200\217\350\247\206\350\241\250 /pivot.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.\351\200\217\350\247\206\350\241\250 /pivot.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "pivot.md", + "notebook_enable": false, + "exercise_id": "88b033cd97c642ef9900e5e091e335ff" +} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" index c322b0d1ec6f003760a96e0650df3415df61f28b..2c8ce8ccaede491b5346463a2666f497a36b1ee9 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "score.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "a4ef62fde91d4f558c6107172ba4f736" } \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\344\272\213\345\212\241/transaction.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\344\272\213\345\212\241/transaction.json" index 7309b3a0e6183dce5c509d90fb7eaa95a31d7c8f..4c56609d4d193007b0e35d17b793ec0193c77d08 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\344\272\213\345\212\241/transaction.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\344\272\213\345\212\241/transaction.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "transaction.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "bce8976b508942bdbe3bd5b6315e7583" } \ No newline at end of file diff --git a/data/tree.json b/data/tree.json index 2c531f4c1403f30a1b182d83180db7762052c24a..0919968dab870f481e6caae74275b7600dbdfc8f 100644 --- a/data/tree.json +++ b/data/tree.json @@ -1,28 +1,28 @@ { "pg": { - "node_id": "pg-4544619de2a54841930282c700ba92b8", + "node_id": "pg-d8b0b9aded4c4cc0b2085d6a7c5611c7", "keywords": [], "children": [ { "PostgreSQL初阶": { - "node_id": "pg-6089aef54c4c4ce7bc85b4dfa14f44cd", + "node_id": "pg-f1c160affc45417a9c5fff7dc4be448a", "keywords": [], "children": [ { "PostgreSQL基本概念": { - "node_id": "pg-b710bd5c63fb4651bebfdd9b3fdb17a5", + "node_id": "pg-1aad17890736469a8b2f61a36dfe41db", "keywords": [], "children": [ { "关系型数据库": { - "node_id": "pg-6920a4f2ba864459bd8883a7a48fa238", + "node_id": "pg-11d131b2d01b40be90b23f096d4852cc", "keywords": [], "children": [] } }, { "服务器和客户端": { - "node_id": "pg-40374311856c4ad3b76fff16ecbe9dce", + "node_id": "pg-cf0e5cb243a247e2a0b812c5798cdba4", "keywords": [], "children": [] } @@ -32,7 +32,7 @@ }, { "PostgreSQL的安装": { - "node_id": "pg-3ac4a2bf31af423fb9e2ec9fe30024c5", + "node_id": "pg-d95edf2d942b45d781e112be785ce260", "keywords": [], "children": [ { @@ -56,7 +56,10 @@ { "使用PostgreSQL": { "node_id": "pg-c252ff4b0e7f4163837c9b6f81678505", - "keywords": [], + "keywords": [ + "login", + "connect" + ], "children": [] } } @@ -65,34 +68,35 @@ }, { "查询数据": { - "node_id": "pg-7e2e52dbddb44d5bad6deea6c5e57198", + "node_id": "pg-30f905f73a574151994d6d7f58d8a20d", "keywords": [], "children": [ { - "SQL基本语法": { - "node_id": "pg-dca8da7637f94ded91a1871daa51746e", + "psql": { + "node_id": "pg-ee5c6d4a073b45a7995ba351ab9de46e", "keywords": [], "children": [] } }, { - "SQL、DML和DDL": { - "node_id": "pg-b0f366abe12e41b0a9672d317e556662", - "keywords": [], - "children": [] - } - }, - { - "PostgreSQL的数据类型": { - "node_id": "pg-1eae8a80615f436081e71b36d89fb0aa", - "keywords": [], + "SQL基本语法": { + "node_id": "pg-dca8da7637f94ded91a1871daa51746e", + "keywords": [ + "语法", + "select" + ], "children": [] } }, { - "函数调用": { - "node_id": "pg-ebef9fceb3684b119a9ba221a81f304b", - "keywords": [], + "SQL、DML和DDL": { + "node_id": "pg-b0f366abe12e41b0a9672d317e556662", + "keywords": [ + "DML", + "insert", + "update", + "delete" + ], "children": [] } } @@ -104,7 +108,7 @@ }, { "PostgreSQL中阶": { - "node_id": "pg-c360138dad92431594130596c5c91394", + "node_id": "pg-fc32585f4136497ea9be2d057d4aeada", "keywords": [], "children": [ { @@ -197,13 +201,6 @@ "children": [] } }, - { - "DML": { - "node_id": "pg-e1cd59819dd74a0bacc707f7863aad53", - "keywords": [], - "children": [] - } - }, { "过程化编程": { "node_id": "pg-eb4048b7dfd3469f8049330ba78427b5", @@ -226,7 +223,7 @@ }, { "PostgreSQL高阶": { - "node_id": "pg-2f46da8212cf41ad9c0d2a5bf1330adc", + "node_id": "pg-c9c7629c52064d8780cbd4dc14dbe351", "keywords": [], "children": [ { @@ -263,13 +260,6 @@ "node_id": "pg-f80410c703044bfea61b2f3a4fbc5705", "keywords": [], "children": [ - { - "自定义类型": { - "node_id": "pg-ec4bbb39e76949b48b13f04cc8c16532", - "keywords": [], - "children": [] - } - }, { "几何类型和GIS": { "node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89", @@ -340,20 +330,6 @@ "keywords": [], "children": [] } - }, - { - "表函数": { - "node_id": "pg-e4b00736ab4c483785c022a0a464f30a", - "keywords": [], - "children": [] - } - }, - { - "结果集类型": { - "node_id": "pg-0e280b203b524a28ab8587aac125a865", - "keywords": [], - "children": [] - } } ] }