欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取当前数据库的所有表和视图的名称

程序员文章站 2024-03-21 21:13:10
...

author:benson

date:2019.05.14 1455


CREATE OR REPLACE VIEW public."tableStructureInfoView" AS
 
  SELECT a.oid AS "tableId",
    a.relname AS name,
    0 AS "isView"

   FROM pg_class a

  WHERE a.relkind = 'r'::"char" AND a.relnamespace = (( SELECT pg_namespace.oid
           FROM pg_namespace
          WHERE pg_namespace.nspname = 'public'::name))
UNION ALL
 SELECT a.oid AS "tableId",
    a.relname AS name,
    1 AS "isView"
    
   FROM pg_class a
  WHERE a.relkind = 'v'::"char" AND a.relnamespace = (( SELECT pg_namespace.oid
           FROM pg_namespace
          WHERE pg_namespace.nspname = 'public'::name));

 
 
ALTER TABLE public."tableStructureInfoView"
    OWNER TO postgres;
COMMENT ON VIEW public."tableStructureInfoView"
    IS '获以当前数据库的所有表和视图的名称';