| | |
| | | show max_connections; |
| | | select count(1) from pg_stat_activity; |
| | | ----------------------------------------------------------------------------------------------------- a.查询表结构 |
| | | select * from pg_tables; |
| | | |
| | |
| | | --alter table lf.sys_menu alter column bak type varchar(1024); |
| | | --alter sequence lf.sys_menu_id_seq restart with 100; |
| | | --update lf.sys_menu set bak=null,create_time=now() where 1=1; |
| | | update lf.sys_menu set order_num=id where 1=1; |
| | | |
| | | select * from lf.sys_menu; |
| | | ----------------------------------------------------------------------------------------------------- 2.单位表 |
| | |
| | | --alter table lf.sys_dep rename short to sname; |
| | | --alter table lf.sys_dep alter column bak type varchar(1024); |
| | | --update lf.sys_dep set bak=null,create_time=now() where 1=1; |
| | | delete from lf.sys_dep where id>44; |
| | | update lf.sys_dep set order_num=id where 1=1; |
| | | |
| | | select * from lf.sys_dep; |
| | | ----------------------------------------------------------------------------------------------------- 3.目录表 |
| | |
| | | |
| | | --select * from public.data_dir; |
| | | --update lf.sys_dir set bak=null,create_time=now(),code=id where 1=1; |
| | | update lf.sys_dir set order_num=id-1000 where id<1050; |
| | | update lf.sys_dir set order_num=id-2000+9 where id<2008 and id>1050; |
| | | update lf.sys_dir set order_num=id-2000+7 where id>2008; |
| | | update lf.sys_dir set order_num=15 where id=2007; |
| | | |
| | | select * from lf.sys_dir; |
| | | select * from lf.sys_dir order by id; |
| | | ----------------------------------------------------------------------------------------------------- 4.用户表 |
| | | -- DROP TABLE IF EXISTS lf.sys_user; |
| | | create table lf.sys_user( |
| | |
| | | select * from lf.sys_login; |
| | | select * from lf.sys_login_2022; |
| | | select * from lf.sys_login_2024; |
| | | ----------------------------------------------------------------------------------------------------- 6.操作日志表 |
| | | ----------------------------------------------------------------------------------------------------- 6.操作日志表 * |
| | | -- DROP TABLE IF EXISTS lf.sys_operate; |
| | | create table lf.sys_operate( |
| | | id serial8, |
| | | modular varchar(60), |
| | | url varchar(256), |
| | | url varchar(1024), |
| | | ip varchar(30), |
| | | exec bigint, |
| | | clazz varchar(100), |
| | | type smallint default 1, |
| | | userid integer default 1, |
| | | optime timestamp(6) without time zone default now() |
| | | optime timestamp(6) without time zone default now(), |
| | | bak varchar(1024) |
| | | ) partition by range(optime); |
| | | |
| | | create table lf.sys_operate_2022 partition of lf.sys_operate for values from ('2022-01-01') to ('2023-01-01'); |
| | |
| | | comment on column lf.sys_operate.modular is '操作模块:如 数据管理\目录管理'; |
| | | comment on column lf.sys_operate.url is '操作网址'; |
| | | comment on column lf.sys_operate.ip is 'IP地址'; |
| | | comment on column lf.sys_operate.type is '类别:1-查看,2-新增,3-修改,4-删除,5-上传,6-下载'; |
| | | comment on column lf.sys_operate.exec is '操作时间:单位为毫秒'; |
| | | comment on column lf.sys_operate.clazz is '类名\方法名'; |
| | | comment on column lf.sys_operate.type is '类别:0-其它,1-查看,2-新增,3-修改,4-删除,5-上传,6-下载'; |
| | | comment on column lf.sys_operate.userid is '操作人ID'; |
| | | comment on column lf.sys_operate.optime is '操作时间'; |
| | | comment on column lf.sys_operate.bak is '备注'; |
| | | |
| | | /*insert into lf.sys_operate (modular,url,ip,type) values ('数据管理\目录管理','data\manage\update','192.168.20.106',5); |
| | | insert into lf.sys_operate (modular,url,ip,type,optime) values ('数据管理\目录管理','data\manage\delete','192.168.20.107',4,'2024-01-02');*/ |
| | | /*insert into lf.sys_operate (modular,url,ip,type) values ('数据管理\目录管理','data/manage/update','192.168.20.106',5); |
| | | insert into lf.sys_operate (modular,url,ip,type,optime) values ('数据管理\目录管理','data/manage/delete','192.168.20.107',4,'2024-01-02');*/ |
| | | |
| | | select * from lf.sys_operate; |
| | | select * from lf.sys_operate_2022; |
| | |
| | | insert into lf.sys_args (name,cvalue,dvalue,descr) values ('缓存有效期',1440,1440,'缓存默认有效期为1440分钟(1天),超时将失效。'); */ |
| | | |
| | | select * from lf.sys_args; |
| | | ----------------------------------------------------------------------------------------------------- 递归查询 |
| | | select * from lf.sys_menu; |
| | | |
| | | with recursive rs as( |
| | | select * from lf.sys_menu where id=1 |
| | | 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 lf.sys_dep; |
| | | |
| | | with recursive rs as( |
| | | select * from lf.sys_dep where id=1 |
| | | union |
| | | select a.* from lf.sys_dep a, rs b where a.pid=b.id |
| | | ) |
| | | select * FROM rs order by level,order_num; |
| | | ------------------------------------------------------------------------------------------------------------------ |
| | | |
| | | |
| | | |
| | | |