diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/config.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/config.json" index 62e02395a34aa38a0c28a1e1493f909cc687fec1..b061382c4e6b72b014c26118bc27bbef0246b9e6 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/config.json" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/config.json" @@ -2,5 +2,5 @@ "node_id": "pg-940afa6d71af44f689011ded8fd91a98", "keywords": [], "children": [], - "export": [] + "export": ["install.json"] } \ 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/1.\345\256\211\350\243\205PostgreSQL/install.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/install.json" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/install.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/install.md" new file mode 100644 index 0000000000000000000000000000000000000000..9fcbd28a0159023537a64e427fe1b73a93fa5f11 --- /dev/null +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/1.\345\256\211\350\243\205PostgreSQL/install.md" @@ -0,0 +1,30 @@ +# 安装 + +下列内容,不正确的是哪一项? + +## 答案 + +安装过程需要 root 权限,也应该将 root 设置为超级用户。 + +## 选项 + +### A + +在 Linux 上,可以用发行版自带的软件安装服务安装,用 systemctl 管理。 + +### B + +在 FreeBSD 上,可以用 ports 安装。 + +### C + +在 windows 上,可以下载安装包进行安装。 + +### D + +PostgreSQL 默认的超级用户名为 postgres 。 + +### E + +修改 postgres.conf 配置文件,可以修改 PG 的监听地址和端口。 + diff --git "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/config.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/config.json" index 76777b0a08e0c54606c2a8a8f8ef85af6ae29d96..964dcc34b2ede3efeaa1810de30966aa1a7a2b4c 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/config.json" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/config.json" @@ -1,6 +1,6 @@ { "node_id": "pg-586916fe52e245efb399ae862378f87f", - "keywords": [], + "keywords": ["登录", "身份验证", "授权"], "children": [], - "export": [] + "export": ["login.json"] } \ 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/2.\347\231\273\345\275\225PostgreSQL/login.json" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.json" index a43082f9041433e1a5d23f01c670a5a9c450de7d..a987293e4f0afd12a75311a0a915727ea3f13bba 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.json" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.json" @@ -1,6 +1,7 @@ { "type": "code_options", "author": "刘鑫", - "source": "grant.md", - "notebook_enable": false + "source": "login.md", + "notebook_enable": false, + "exercise_id": "54917a4c69af41749d1c2a4430267f27" } \ 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/2.\347\231\273\345\275\225PostgreSQL/login.md" "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.md" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..038122fc15a4da9006ec0e4a424eb7721f16fd7f 100644 --- "a/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.md" +++ "b/data/1.PostgreSQL\345\210\235\351\230\266/2.PostgreSQL\347\232\204\345\256\211\350\243\205/2.\347\231\273\345\275\225PostgreSQL/login.md" @@ -0,0 +1,60 @@ +# 登录 + +你的团队有一个公用的开发服务器,你要安装一个 PostgreSQL 服务公用,你们希望每位同事 +使用一个独立的开发数据库,不互相混淆。同时这个服务器不向其他部门开放。数据也希望有足 +够的安全保障。你的同事们都有这台开发服务器的 ssh 账号,平时远程登录到服务器上工作。 +下面哪个组合最符合你们的需求? + +1. 为每位同事建立一个数据库账号 +2. 初始化口令为123456,告知他们登录后修改密码。 +3. 为每位同事建立对应的开发数据库,将他们的用户设置为该数据库的 owner +4. 将每位同事的用户身份都设置为superuser,并禁止他们登录别人的数据库 +5. 为每位同事建立一个与操作系统账号同名的数据库账号 +6. 修改 pg_hba.conf ,设置本地用户可以用操作系统集成登录 +7. 设置 postgres 账号口令为 123456,群发告知同事 + +## 答案 + +``` +5, 3, 6 +``` + +## 选项 + + +### A + +``` +1, 2, 4 +``` + +### B + +``` +1, 2, 4, 6 +``` + +### C + +``` +5, 2, 4 +``` + +### D + +``` +5, 2, 4, 6 +``` + + +### E + +``` +7, 6 +``` + +### F + +``` +2, 3, 4, 5, 6, 7 +``` \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" index a43082f9041433e1a5d23f01c670a5a9c450de7d..3122a7ed8c21aad999000212322821ba61de7e92 100644 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" +++ "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "grant.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "0766e022b61f4c83b4fe64cd8e4e5e9b" } \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" index 52f14c6b8277d7079591692ae16ccb5ed2b86146..a5bda79ebf7d471b191742cccf784d08ad166ac1 100644 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" +++ "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "revoke.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "65de2267ccb7478db916d517d4b5bce7" } \ No newline at end of file diff --git "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" index 52051d6fde055ffc296430b3327608f955c65329..3ae818a7e1107263b3b72cd96182d4c618fd5f8a 100644 --- "a/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" +++ "b/data/2.PostgreSQL\344\270\255\351\230\266/1.PostgreSQL\346\225\260\346\215\256\345\272\223\347\232\204\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "role.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "f093e146721541139080bc01ffd39750" } \ 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/4.\345\210\206\351\241\265\346\237\245\350\257\242/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/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" index be76b4efd44281ef8ba6f9be0e9cfd3ff99326d2..42ce499f78ee2e8074f8869b7a4f02fcddb5981b 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/4.\345\210\206\351\241\265\346\237\245\350\257\242/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/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" @@ -2,5 +2,5 @@ "node_id": "pg-69d3a1c646004e1da497fed2af57806c", "keywords": [], "children": [], - "export": [] + "export": ["paged.json"] } \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" new file mode 100644 index 0000000000000000000000000000000000000000..ed265c3f785dd66ed4e45591abe37074d7a472e2 --- /dev/null +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "backup.md", + "notebook_enable": false +} \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" new file mode 100644 index 0000000000000000000000000000000000000000..ecfe8b2d79c5f69814e3ea1df45f5a3ba1cd38d3 --- /dev/null +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" @@ -0,0 +1,41 @@ +# 高可靠备份 + +你的团队有一个非常重要的业务数据库,希望在需要时,可以重建它在一周内任意某个时间点的状态。下列规划中不必要的是: + +1. 对 WAL 日志建立备份,按时间保留所有的 WAL 文件作为增量备份 +2. 每天做一次冷备 +3. 需要重现时,用离目标时间点最近的前一次冷备恢复一个数据库节点,启动为 standby 状态,用对应的 wal 恢复。 +4. 建立流备份节点 +5. 每天非高峰期将数据库离线,完整复制一份数据区目录 + +## 答案 + +``` +4, 5 +``` + +## 选项 + +### A + +``` +1, 2 +``` + +### B + +``` +3 +``` + +### C + +``` +以上所有工作都需要,没有多余项 +``` + +### D + +``` +2, 4 +``` \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" index 7e6d65fb62a163c10ebb702c44af64fbe7115a8e..2ab941ee9865967257ce1859ef66d22e6642add8 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" @@ -2,5 +2,8 @@ "node_id": "pg-58e924e93b564a24abb1e6b9cdfbc094", "keywords": [], "children": [], - "export": ["standby.json"] + "export": [ + "standby.json", + "backup.json" + ] } \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" index ef45c01fdb9db43ba3ec1777fb98195b4ac1e8ee..e258fff3876c88fdd5e0296aaf07943500340cf8 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "standby.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "491d9bdd19c04279ac607b73a63bb3e6" } \ No newline at end of file diff --git "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" index 66a7642c32f33ad337e3e724847b6f2914ff20c0..aaccf6ce1d6b77a19dc1f0971b231013bd783f24 100644 --- "a/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" +++ "b/data/3.PostgreSQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "stream.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "061bfb92b674438cb56a6cf72c406cbb" } \ 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" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5ef2622a00282644015139dee5887ee560448162 100644 --- "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" @@ -0,0 +1,6 @@ +{ + "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/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" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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" new file mode 100644 index 0000000000000000000000000000000000000000..a51534d433d9af72138b8e8f522a1f89f8d17cf9 --- /dev/null +++ "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" @@ -0,0 +1,56 @@ +# 匹配 + +表 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" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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" new file mode 100644 index 0000000000000000000000000000000000000000..b15550792a7f463effc4fd4875b976e10650c575 --- /dev/null +++ "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" @@ -0,0 +1,46 @@ +# 标签 + +现有一个表 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/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" index 65fd37fb393a74ded608a984965ff589a9e236a0..ac7d27463eeb856e89d6c2974297b68cd17c3c82 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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "daily_payment.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "5e355cc9197a4d02a54f045301c88ace" } \ 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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" index 3e60c8a925cb47dcf165e8ba80432bad3b03bed6..44e5be5fed1fe593cffa16bb06b95250123852a6 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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.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.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" @@ -2,5 +2,6 @@ "type": "code_options", "author": "刘鑫", "source": "daily_payment_2.md", - "notebook_enable": false + "notebook_enable": false, + "exercise_id": "9295152720b74c65a0236cec175f6dce" } \ No newline at end of file