Skip to content

Commit c2bdbbc

Browse files
authored
Dev (#2)
* Update
1 parent 532f4d8 commit c2bdbbc

File tree

8 files changed

+83
-24
lines changed

8 files changed

+83
-24
lines changed
File renamed without changes.
File renamed without changes.

docs/SQL1/PostGIS1/index.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
comments: true
3+
tags:
4+
- GIS
5+
---
6+
7+
# PostGIS
8+
9+
## 安装
10+
11+
```sql
12+
CREATE SCHEMA postgis;
13+
GRANT USAGE ON schema postgis to public;
14+
15+
CREATE EXTENSION postgis SCHEMA postgis;
16+
CREATE EXTENSION postgis_raster SCHEMA postgis;
17+
18+
ALTER DATABASE postgis_in_action SET search_path=public,postgis,contrib;
19+
```
20+
21+
!!! info "提示"
22+
虽然不是必需的,但建议在单独的模式(如 postgis)中安装 postgis,这样函数就不会弄乱默认的公共模式。
23+
24+
## 查询数据库下所有空间表
25+
26+
```sql
27+
WITH columns AS (
28+
SELECT
29+
ns.nspname AS table_schema, -- 模式
30+
cls.relname AS table_name, -- 表名
31+
cls.reltuples AS tuples, -- 记录数
32+
des.description AS description, -- 表描述
33+
attr.attname AS column_name, -- 列名
34+
col_description(attr.attrelid, attr.attnum) AS column_comment, -- 列描述
35+
trim(leading '_' from tp.typname) AS column_type -- 列类型
36+
FROM pg_catalog.pg_attribute attr
37+
JOIN pg_catalog.pg_class AS cls ON cls.oid = attr.attrelid
38+
JOIN pg_catalog.pg_namespace AS ns ON ns.oid = cls.relnamespace
39+
JOIN pg_catalog.pg_type AS tp ON tp.oid = attr.atttypid
40+
JOIN pg_catalog.pg_description AS des ON cls.oid = des.objoid AND des.objsubid = 0
41+
WHERE
42+
NOT attr.attisdropped
43+
AND attr.attnum > 0
44+
AND cls.relname NOT LIKE 'pg_%'
45+
AND ns.nspname NOT IN ('pg_catalog', 'information_schema')
46+
-- AND ns.nspname = 'other'
47+
-- AND cls.relname like 'flash_flood_hazard_point'
48+
)
49+
SELECT
50+
f_table_name as id,
51+
f_table_schema as workspace,
52+
f_table_name as data_name,
53+
columns.description as description,
54+
columns.tuples as tuples,
55+
f_geometry_column as geometry_column,
56+
type as geometry_type,
57+
srid,
58+
jsonb_object_agg(
59+
columns.column_name,
60+
json_build_object(
61+
'type',columns.column_type,
62+
'title',columns.column_comment
63+
)
64+
) AS fields
65+
FROM postgis.geometry_columns as gc
66+
JOIN columns ON
67+
gc.f_table_schema = columns.table_schema AND
68+
gc.f_table_name = columns.table_name AND
69+
gc.f_geometry_column != columns.column_name
70+
GROUP BY f_table_schema, f_table_name, description, tuples, f_geometry_column, srid, type
71+
72+
```

docs/SQL1/PostgreSQL1/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PostgreSQL
2+
3+
## 修改字段类型
4+
5+
```sql
6+
-- 不带转换
7+
ALTER TABLE table_name ALTER COLUMN column_name TYPE new_type;
8+
9+
-- 带转换
10+
ALTER TABLE table_name ALTER COLUMN column_name TYPE new_type USING column_name::new_type;
11+
```
File renamed without changes.

docs/python/geopandas.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/python/index.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/sql/postgis/index.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)