• 查询postgresql表结构和索引


    通过系统数据字典查询表结构

    select
    col.table_schema,
    col.table_name,
    col.ordinal_position,
    col.column_name,
    col.data_type,
    col.character_maximum_length,
    col.numeric_precision,
    col.numeric_scale,
    col.is_nullable,
    col.column_default,
    des.description
    from
    information_schema.columns col left join pg_description des on
    col.table_name::regclass = des.objoid
    and col.ordinal_position = des.objsubid
    where
    table_schema = 'public'
    and table_name = 't_student'
    order by
    ordinal_position;

    select * from information_schema.columns
    where table_schema='public' and table_name='t_student';

    通过系统数据字典查询索引信息


    select
    A.SCHEMANAME,
    A.TABLENAME,
    A.INDEXNAME,
    A.TABLESPACE,
    A.INDEXDEF,
    B.AMNAME,
    C.INDEXRELID,
    C.INDNATTS,
    C.INDISUNIQUE,
    C.INDISPRIMARY,
    C.INDISCLUSTERED,
    D.DESCRIPTION
    from
    PG_AM B left join PG_CLASS F on
    B.OID = F.RELAM left join PG_STAT_ALL_INDEXES E on
    F.OID = E.INDEXRELID left join PG_INDEX C on
    E.INDEXRELID = C.INDEXRELID left outer join PG_DESCRIPTION D on
    C.INDEXRELID = D.OBJOID,
    PG_INDEXES A
    where
    A.SCHEMANAME = E.SCHEMANAME
    and A.TABLENAME = E.RELNAME
    and A.INDEXNAME = E.INDEXRELNAME
    and E.SCHEMANAME = 'public'
    and E.RELNAME = 't_student';


    查询所有的表名
    select
    n.nspname,
    relname
    from
    pg_class c,
    pg_namespace n
    where
    c.relnamespace = n.oid
    and nspname = 'public'
    and relkind = 'r'
    order by
    relname;

  • 相关阅读:
    11-8 Eureka Server整合SpringSecurity解决安全问题
    11-7 Eureka Server安全问题介绍
    11-6 CORS跨域资源共享解决
    11-5 JWT验证演示
    11-4 JWT验证开发演示
    11-3 JWT颁发流程讲解
    11-2 JWT介绍
    11-1 服务安全章节介绍
    10-15 Zuul知识点梳理
    10-14 Zuul与Meetingfilm整合
  • 原文地址:https://www.cnblogs.com/zhian/p/14083175.html
Copyright © 2020-2023  润新知