PostgreSQL高级sql积累

1:----查询postgresql数据中系统表与自己建立表结构做了个对比

select cl.relname,att.attname,att.atttypid,f.* from pg_class cl

LEFT JOIN pg_attribute att on att.attrelid = cl.oid

LEFT JOIN td_f_field_info f on f.party_table_name=cl.relname and f.field_name=att.attname

-- LEFT JOIN pg_type t on

where cl.relname like 'dpm%'

and att.attname not like '........pg%'

and cl.relname not like '%pkey%'

and f.id is null

and att.attnum>0

ORDER BY cl.relname;

2:------

SELECT f.* from td_f_step_table_rel r

LEFT JOIN td_f_table_info t on r.table_id=t.id

LEFT JOIN td_f_field_info f on t.party_table_name=f.party_table_name

where r.flow_step_id='2' and r.flow_sub_step_id='4' ORDER BY t.party_table_name;

3:将表dpm_5_base_person中的数据 循环添加进 td_f_field_info

INSERT into td_f_field_info(id,party_table_name,field_name,data_type,description )

(select uuid_generate_v1(),cl.relname,att.attname,t.typname,col_description(att.attrelid,att.attnum) from pg_class cl

LEFT JOIN pg_attribute att on att.attrelid = cl.oid

LEFT JOIN td_f_field_info f on f.party_table_name=cl.relname and f.field_name=att.attname

LEFT JOIN pg_type t on att.atttypid=t.oid

where cl.relname like 'dpm_5_base_person'

and att.attname not like '........pg%'

and cl.relname not like '%pkey%'

and f.id is null

and att.attnum>0

ORDER BY cl.relname) ;

4:-- 将表字段存在但是field_info中不存在的字段插入到field_info中

INSERT into td_f_field_info(id,party_table_name,field_name,data_type,description, is_null,max_length )

(select uuid_generate_v1(),cl.relname,att.attname,t.typname,col_description(att.attrelid,att.attnum),

(case att.attnotnull when 't' then '0' else '1' end),

(CASE WHEN att.atttypmod >=4 THEN att.atttypmod- 4 WHEN att.atttypmod

from pg_class cl

LEFT JOIN pg_attribute att on att.attrelid = cl.oid

LEFT JOIN td_f_field_info f on f.party_table_name=cl.relname and f.field_name=att.attname

LEFT JOIN pg_type t on att.atttypid=t.oid

where cl.relname like 'dpm_2_6_inspect_option%'

and att.attname not like '........pg%'

and cl.relname not like '%pkey%'

and f.id is null

and att.attnum>0

ORDER BY cl.relname) ;

5:postgreSql中char类型的数据,如果长度设为8 不足8个字符的字符串会自动补空格 比如值为'123' 存到数据库里实际为'123 '

6:INSERT INTO "public"."td_f_approve_defined" ("task_id", "step_id", "step_name", "sub_step_id", "sub_step_name", "approve_role", "update_date", "update_by", "level", "version", "person_name", "create_by", "create_date", "del_flag") VALUES ('2', '1', '申请入党', '2', '党组织谈话', '4', '2018-05-07 13:50:39', '11', '1', '1', '11', '1', '2018-05-07 13:51:00', '0');

添加td_f_approval_define 表中数据

7:select * from tf_f_org where length(code)=18

select * from tf_f_org where length(code)=24 and org_name like '%海洋%'

--梁山县

select * from tf_f_org where length(code)=24 and code LIKE '000002000008000011%'

--中共青岛经济技术开发区工作委员会

select * from tf_f_org where length(code)=24 and parent_id='d367736e-57de-11e7-b7aa-0050569a68e4';

SELECT * FROM "public"."tf_f_org" WHERE "org_name" LIKE '%潍坊滨海经济技术开发区%' LIMIT 1000 OFFSET 0

汇总 单项汇总

相关推荐

  1. PostgreSQL高级sql积累

    2024-04-12 23:18:02       15 阅读
  2. PostgreSQL数据库高级sql总结2

    2024-04-12 23:18:02       10 阅读
  3. Postgresql数据库高级sql总结3

    2024-04-12 23:18:02       11 阅读
  4. <span style='color:red;'>sql</span><span style='color:red;'>高级</span>

    sql高级

    2024-04-12 23:18:02      24 阅读
  5. sql常用函数积累(非窗口函数)

    2024-04-12 23:18:02       32 阅读
  6. SQL高级:窗口函数

    2024-04-12 23:18:02       38 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-12 23:18:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-12 23:18:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-12 23:18:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-12 23:18:02       18 阅读

热门阅读

  1. 基于springboot的车辆管理系统源码数据库

    2024-04-12 23:18:02       20 阅读
  2. vue3表格编辑(数据回显)和删除功能实现

    2024-04-12 23:18:02       19 阅读
  3. 【NC23803】DongDong认亲戚

    2024-04-12 23:18:02       55 阅读
  4. 【华为OD机试C++】蛇形矩阵

    2024-04-12 23:18:02       17 阅读
  5. 【算法刷题day24】回溯算法+简单剪枝

    2024-04-12 23:18:02       75 阅读
  6. 虚拟线程和普通线程

    2024-04-12 23:18:02       15 阅读
  7. 递归神经网络(Recursive Neural Networks)

    2024-04-12 23:18:02       16 阅读