管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-08 5fd15c6bde114750fe4522257e66dc33451b173b
1
已修改1个文件
50 ■■■■■ 文件已修改
data/db.sql 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db.sql
@@ -1,3 +1,5 @@
-----------------------------------------------------------------------------------------------------
show max_connections;
select count(1) from pg_stat_activity;
----------------------------------------------------------------------------------------------------- a.查询表结构
@@ -918,48 +920,34 @@
select * from lf.sys_args;
----------------------------------------------------------------------------------------------------- 递归查询
--------------------------------------------------------- 查询菜单
select * from lf.sys_menu;
with recursive rs as(
  select * from lf.sys_menu where id=1
  select * from lf.sys_menu where cn_name='管道基础大数据平台'
union
  select a.* from lf.sys_menu a, rs b where a.pid=b.id
)
select * FROM rs order by level||'-'||order_num;
---------------------------------------------------------
with recursive rs as(
  select a.* from lf.sys_menu a where id = 1
union
  select b.* from lf.sys_menu b
  inner join rs on b.pid = rs.id
)
select * FROM rs order by level,order_num
-- API 如下
connectby(text relname,             -- 表名称
  text keyid_fld,           -- id字段
  text parent_keyid_fld     -- 父id字段
  [, text orderby_fld ],    -- 排序字段
  text start_with,          -- 起始行的id值
  int max_depth             -- 树深度,0表示无限
  [, text branch_delim ])   -- 路径分隔符
-- 基本用法如下,必须通过AS子句定义返回的字段名称和类型
select *
    from connectby('demo.tree_data', 'id', 'pid', 'sort', '1', 0, '~')
    as (id int, pid int, lvl int, branch text, sort int);
select * from connectby('lf.sys_menu','id','pid','order_num','1',0,'-')
select * FROM rs order by order_num;
--------------------------------------------------------- 查询单位
select * from lf.sys_dep;
with recursive rs as(
  select * from lf.sys_dep where id=1
  select * from lf.sys_dep where name='中国石油天然气管道工程有限公司'
union
  select a.* from lf.sys_dep a, rs b where a.pid=b.id
)
select * FROM rs order by level,order_num;
------------------------------------------------------------------------------------------------------------------
select * FROM rs order by order_num;
--------------------------------------------------------- 数据目录
select * from lf.sys_dir;
with recursive rs as(
  select * from lf.sys_dir where name='中俄东线管道工程南段'
union
  select a.* from lf.sys_dir a, rs b where a.pid=b.id
)
select * FROM rs order by order_num;
-----------------------------------------------------------------------------------------------------