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.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/7.DDL/config.json" index 4831a2bf47658609a3a75e138d552b686b49abcd..2c27754d4f64ff8f9d47eaa9d172576c8f93d739 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/7.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/7.DDL/config.json" @@ -4,6 +4,6 @@ "children": [], "export": [ "create_table.json", - "anylze.json" + "analyze.json" ] } \ 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/1.\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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" index b99d8b54997bf034899150b1cce368a47da36d3a..9a79271c48aaf466ae4c9d9602be04ec2541c51b 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/1.\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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" @@ -1,6 +1,6 @@ { "node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89", - "keywords": [], + "keywords": ["gis", "地理信息"], "children": [], - "export": [] + "export": ["gis.json"] } \ 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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" new file mode 100644 index 0000000000000000000000000000000000000000..a8279b3148ff2a3845971dfdb90b71b71056ecb2 --- /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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "gis.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/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" new file mode 100644 index 0000000000000000000000000000000000000000..3d54b4a6af201646b00604bb8506f7076bd857ad --- /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/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" @@ -0,0 +1,66 @@ +# 邻近查找 + +我们有一个简化的表结构如下: + +```postgresql +create table city +( + id serial8, + city text, + poi point +); +create index idx_tbl_point on city using gist (poi) with (buffering = on); +``` + +要查找给定的点位于哪个城市,或者离哪个城市最近,应该是下列哪一项? + +## 答案 + +```postgresql +select city, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +order by poi <-> point($1, $2) +limit 1; +``` + +## 选项 + +### A + +```postgresql +select city, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +order by poi <-> point($1, $2) desc +limit 1; +``` + +### B + +```postgresql +select *, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +limit 1; +``` + +### C + +```postgresql +select *, poi - point($1, $2) dist +from city +where poi - point($1, $2) < 100 +order by poi - point($1, $2) +limit 1; +``` + +### D + +```postgresql +select *, abs(poi - point($1, $2)) dist +from city +where abs(poi - point($1, $2)) < 100 +order by abs(poi - point($1, $2)) +limit 1; +``` \ No newline at end of file diff --git a/data/tree.json b/data/tree.json index 0919968dab870f481e6caae74275b7600dbdfc8f..669c8cf432ce965ef56be649aa4c295d5829edf6 100644 --- a/data/tree.json +++ b/data/tree.json @@ -211,7 +211,11 @@ { "DDL": { "node_id": "pg-0378bcd60ccd4dfebcfead92abbdd673", - "keywords": [], + "keywords": [ + "创建表", + "授权", + "ddl" + ], "children": [] } } @@ -263,7 +267,10 @@ { "几何类型和GIS": { "node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89", - "keywords": [], + "keywords": [ + "gis", + "地理信息" + ], "children": [] } },