当前位置: 首页 > news >正文

PostgreSQL 查询数据表、视图信息

--获得指定schema范围内的所有表和视图的列表,可指定一个排除表前缀模式
with param as (select 'public,iit' as schema_name,'db2g%' as exclude_pattern),base_info as (--获得所有基表select pg_namespace.nspname as schema_name, a.relname as tbl_name ,'TBL' as tbl_type, b.description as tbl_commentfrom pg_class ajoin pg_namespace on a.relnamespace=pg_namespace.oidleft join (select * from pg_description where objsubid =0 ) bon a.oid = b.objoidwhere a.relkind='r'and a.relname not like (select exclude_pattern from param)and pg_namespace.nspname in (select regexp_split_to_table(schema_name,',') from param)union all---获取所有视图SELECT schemaname as schema_name, viewname as tbl_name,'VW' as tbl_type, null as tbl_commentFROM pg_viewsWHERE schemaname in (select regexp_split_to_table(schema_name,',') from param))
select * from base_info;
--获得指定schema范围内的所有表和视图的数据列信息,可指定一个排除表前缀模式
with param as (select 'public,iit' as schema_name,'db2g%' as exclude_pattern),base_info as (select table_schema, table_name, ordinal_position                                                      as Colorder, column_name                                                           as ColumnName, data_type                                                             as TypeName, coalesce(character_maximum_length, numeric_precision, -1)             as Length, numeric_scale                                                         as Scale, case is_nullable when 'NO' then 0 else 1 end                          as CanNull, column_default                                                        as DefaultVal, case when position('nextval' in column_default) > 0 then 1 else 0 end as IsIdentity, case when b.pk_name is null then 0 else 1 end                         as IsPK, c.DeTextfrom information_schema.columnsleft join (select pg_attr.attname as colname,pg_constraint.conname as pk_name,pg_class.relname as tblname,pg_namespace.nspname as schema_namefrom pg_constraintjoin pg_class on pg_constraint.conrelid = pg_class.oidjoin pg_attribute pg_attr on pg_attr.attrelid = pg_class.oidand pg_attr.attnum = pg_constraint.conkey[1]join pg_type on pg_type.oid = pg_attr.atttypidjoin pg_namespace on pg_constraint.connamespace=pg_namespace.oidwhere pg_constraint.contype = 'p') b on b.colname = information_schema.columns.column_nameand b.tblname=information_schema.columns.table_nameand b.schema_name=information_schema.columns.table_schemaleft join (select attname, description as DeText, pg_class.relname as tblname,pg_namespace.nspname as schema_namefrom pg_classjoin pg_namespace on pg_class.relnamespace=pg_namespace.oidleft join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oidleft join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelidand pg_desc.objsubid = pg_attr.attnumwhere pg_attr.attnum > 0and pg_attr.attrelid = pg_class.oid) c on c.attname = information_schema.columns.column_nameand c.tblname=information_schema.columns.table_nameand c.schema_name=information_schema.columns.table_schemawhere table_schema in (select regexp_split_to_table(schema_name,',') from param)and table_name not like (select exclude_pattern from param)order by table_name,ordinal_position)
select * from base_info;

--查询指定模式下的表和视图with param as (select 'public' as schema_name,'db2g%' as exclude_pattern)
--获得所有基表
select a.relname as tbl_name ,'TBL' as tbl_type, b.description as tbl_comment
from pg_class aleft join (select *from pg_description where objsubid =0 ) bon a.oid = b.objoid
where a.relname in (select tablenamefrom pg_tableswhere schemaname = (select schema_name from param))and a.relname not like (select exclude_pattern from param)
union all
---获取所有视图
SELECT viewname as tbl_name,'VW' as tbl_type, null as tbl_comment
FROM pg_views
WHERE schemaname =(select schema_name from param)
order by tbl_name asc;

--查询指定数据基表的列信息

with param as (select 'emp' as tblname),base_info as (select ordinal_position                                                      as Colorder, column_name                                                           as ColumnName, data_type                                                             as TypeName, coalesce(character_maximum_length, numeric_precision, -1)             as Length, numeric_scale                                                         as Scale, case is_nullable when 'NO' then 0 else 1 end                          as CanNull, column_default                                                        as DefaultVal, case when position('nextval' in column_default) > 0 then 1 else 0 end as IsIdentity, case when b.pk_name is null then 0 else 1 end                         as IsPK, c.DeTextfrom information_schema.columnsleft join (select pg_attr.attname as colname, pg_constraint.conname as pk_namefrom pg_constraintjoin pg_class on pg_constraint.conrelid = pg_class.oidjoin pg_attribute pg_attr on pg_attr.attrelid = pg_class.oidand pg_attr.attnum = pg_constraint.conkey[1]join pg_type on pg_type.oid = pg_attr.atttypidwhere pg_class.relname = (select tblname from param)and pg_constraint.contype = 'p') b on b.colname = information_schema.columns.column_nameleft join (select attname, description as DeTextfrom pg_classleft join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oidleft join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelidand pg_desc.objsubid = pg_attr.attnumwhere pg_attr.attnum > 0and pg_attr.attrelid = pg_class.oidand pg_class.relname = (select tblname from param)) c on c.attname = information_schema.columns.column_namewhere table_schema = 'public'and table_name = (select tblname from param)order by ordinal_position asc)
select * from base_info

相关文章:

PostgreSQL 查询数据表、视图信息

--获得指定schema范围内的所有表和视图的列表,可指定一个排除表前缀模式with param as (select public,iit as schema_name,db2g% as exclude_pattern),base_info as (--获得所有基表select pg_namespace.nspname as schema_name, a.relname as tbl_name ,TBL as tb…...

手撕vector容器

一、vector容器的介绍 vector是表示可变大小数组的序列容器。就像数组一样,vector也采用的连续存储空间来存储元素,但是又不像数组,它的大小是可以动态改变的,而且它的大小会被容器自动处理。 总结:vector是一个动态…...

PyMuPDF`库实现PDF旋转功能

本文介绍了一个简单的Python应用程序,用于将PDF文件转换为旋转90度的PDF文件。主要用于csdn网站中导出的博客pdf是横向的,看起来不是很方便,才想到用python编制一个将pdf从横向转为纵向的功能。 功能 该PDF转换工具具有以下功能&#xff1a…...

微人事 登录问题完善

重启服务端的时候,发现前端页面会操作不了,这样后端session会失效,我们就需要让页面重新跳转到登录页 springsecurity配置类后端配置 前端拦截器进行拦截跳转...

【业务功能篇64】安装docker容器,在docker上安装mysql

docker教程: https://www.runoob.com/docker/docker-tutorial.html卸载docker 较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。 yum remove docker docker-client docker-client-latest docker-co…...

MyBatis的基本概念和核心组件

MyBatis的基本概念 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Pla…...

sql update执行返回0,能否判断数据不存在

答案:不能。 update执行返回0的情况 1、没有找到需要更新的数据,就是这条记录不存在 例如:where后面的条件是id0,那这条记录肯定是不存在的,返回结果是0 2、更新时的数据和要更新的数据完全一致时 例如:更…...

数据分析 | 调用Optuna库实现基于TPE的贝叶斯优化 | 以随机森林回归为例

1. Optuna库的优势 对比bayes_opt和hyperoptOptuna不仅可以衔接到PyTorch等深度学习框架上,还可以与sklearn-optimize结合使用,这也是我最喜欢的地方,Optuna因此特性可以被使用于各种各样的优化场景。 2. 导入必要的库及加载数据 用的是sklea…...

stm32单片机开关输入控制蜂鸣器参考代码(附PROTEUS电路图)

说明:这个buzzer的额定电压需要改为3V,否则不会叫,源代码几乎是完全一样的 //gpio.c文件 /* USER CODE BEGIN Header */ /********************************************************************************* file gpio.c* brief Thi…...

打印X型的图案

int main() {int n0;int i0;int j0;scanf("%d",&n);for(i0;i<n;i){for(j0;j<n;j){if(ij){printf("*");}else if((ij)n-1){printf("*");}elseprintf(" ");}printf("\n");}return 0; }...

不含数字的webshell绕过

异或操作原理 1.首先我们得了解一下异或操作的原理 在php中&#xff0c;异或操作是两个二进制数相同时&#xff0c;异或(相同)为0&#xff0c;不同为1 举个例子 A的ASCII值是65&#xff0c;对应的二进制值是0100 0001 的ASCII值是96&#xff0c;对应的二进制值是 0110 000…...

Mac上传项目源代码到GitHub的修改更新

Mac上传项目源代码到GitHub的修改更新 最近在学习把代码上传到github&#xff0c;不得不说&#xff0c;真的还挺方便 这是一个关于怎样更新项目代码的教程。 首先&#xff0c;在本地终端命令行打开至项目文件下第一步&#xff1a;查看当前的git仓库状态&#xff0c;可以使用git…...

Android6:片段和导航

创建项目Secret Message strings.xml <resources><string name"app_name">Secret Message</string><string name"welcome_text">Welcome to the Secret Message app!Use this app to encrypt a secret message.Click on the Star…...

ClickHouse AST is too big 报错问题处理记录

ClickHouse AST is too big 报错问题处理记录 问题描述问题分析解决方案1、修改系统配置2、修改业务逻辑 问题描述 项目中统计报表的查询出现 AST is too big 问题&#xff0c;报错信息如下&#xff1a; 问题分析 报错信息显示 AST is too big。 AST 表示查询语法树中的最大…...

DPDK系列之二十七DIDO

一、DIDO介绍 随着计算机技术发展&#xff0c;特别是应用技术的快速发展。应用场景对计算机的处理速度几乎已经到了疯狂的地步。说句大白话&#xff0c;再快的CPU也嫌慢。没办法&#xff0c;CPU和IO等技术基本目前都处在了瓶颈之处&#xff0c;大幅度提高&#xff0c;短时间内…...

《游戏编程模式》学习笔记(七)状态模式 State Pattern

状态模式的定义 允许对象在当内部状态改变时改变其行为&#xff0c;就好像此对象改变了自己的类一样。 举个例子 在书的示例里要求你写一个人物控制器&#xff0c;实现跳跃功能 直觉上来说&#xff0c;我们代码会这么写&#xff1a; void Heroine::handleInput(Input input…...

博客系统之功能测试

博客系统共有&#xff1a;用户登录功能、发布博客功能、查看文章详情功能、查看文章列表功能、删除文章功能、退出功能 1.登录功能&#xff1a; 1.1测试对象&#xff1a;用户登录 1.2测试用例 方法&#xff1a;判定表 用例 编号 操作步骤预期结果实际结果截图1 1.用户名正确…...

CJS和 ES6 的语法区别

CommonJS 使用 module.exports 导出模块。ES6 使用 export 导出模块。 示例代码&#xff1a; CommonJS&#xff08;CJS&#xff09;模块的导出&#xff1a; // 导出模块 module.exports {foo: bar,baz: function() {return qux;} }; ES6 模块的导出&#xff1a; // 导出模…...

ArcGIS Pro如何制作不规则形状图例

在默认的情况下&#xff0c;ArcGIS Pro生成的图例是标准的点、直线和矩形的&#xff0c;对于湖泊等要素而言&#xff0c;这样的表示方式不够直观&#xff0c;我们可以将其优化一下&#xff0c;制作不规则的线和面来代替原有图例&#xff0c;这里为大家介绍一下制作方法&#xf…...

微软Win11 Dev预览版Build23526发布

近日&#xff0c;微软Win11 Dev预览版Build23526发布&#xff0c;修复了不少问题。牛比如斯Microsoft&#xff0c;也有这么多bug&#xff0c;所以你写再多bug也不作为奇啊。 主要更新问题 [开始菜单&#xff3d; 修复了在高对比度主题下&#xff0c;打开开始菜单中的“所有应…...

Linux 文件类型,目录与路径,文件与目录管理

文件类型 后面的字符表示文件类型标志 普通文件&#xff1a;-&#xff08;纯文本文件&#xff0c;二进制文件&#xff0c;数据格式文件&#xff09; 如文本文件、图片、程序文件等。 目录文件&#xff1a;d&#xff08;directory&#xff09; 用来存放其他文件或子目录。 设备…...

ES6从入门到精通:前言

ES6简介 ES6&#xff08;ECMAScript 2015&#xff09;是JavaScript语言的重大更新&#xff0c;引入了许多新特性&#xff0c;包括语法糖、新数据类型、模块化支持等&#xff0c;显著提升了开发效率和代码可维护性。 核心知识点概览 变量声明 let 和 const 取代 var&#xf…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地

借阿里云中企出海大会的东风&#xff0c;以**「云启出海&#xff0c;智联未来&#xff5c;打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办&#xff0c;现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...

visual studio 2022更改主题为深色

visual studio 2022更改主题为深色 点击visual studio 上方的 工具-> 选项 在选项窗口中&#xff0c;选择 环境 -> 常规 &#xff0c;将其中的颜色主题改成深色 点击确定&#xff0c;更改完成...

高危文件识别的常用算法:原理、应用与企业场景

高危文件识别的常用算法&#xff1a;原理、应用与企业场景 高危文件识别旨在检测可能导致安全威胁的文件&#xff0c;如包含恶意代码、敏感数据或欺诈内容的文档&#xff0c;在企业协同办公环境中&#xff08;如Teams、Google Workspace&#xff09;尤为重要。结合大模型技术&…...

WEB3全栈开发——面试专业技能点P2智能合约开发(Solidity)

一、Solidity合约开发 下面是 Solidity 合约开发 的概念、代码示例及讲解&#xff0c;适合用作学习或写简历项目背景说明。 &#x1f9e0; 一、概念简介&#xff1a;Solidity 合约开发 Solidity 是一种专门为 以太坊&#xff08;Ethereum&#xff09;平台编写智能合约的高级编…...

【python异步多线程】异步多线程爬虫代码示例

claude生成的python多线程、异步代码示例&#xff0c;模拟20个网页的爬取&#xff0c;每个网页假设要0.5-2秒完成。 代码 Python多线程爬虫教程 核心概念 多线程&#xff1a;允许程序同时执行多个任务&#xff0c;提高IO密集型任务&#xff08;如网络请求&#xff09;的效率…...

Hive 存储格式深度解析:从 TextFile 到 ORC,如何选对数据存储方案?

在大数据处理领域&#xff0c;Hive 作为 Hadoop 生态中重要的数据仓库工具&#xff0c;其存储格式的选择直接影响数据存储成本、查询效率和计算资源消耗。面对 TextFile、SequenceFile、Parquet、RCFile、ORC 等多种存储格式&#xff0c;很多开发者常常陷入选择困境。本文将从底…...

scikit-learn机器学习

# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...

【Android】Android 开发 ADB 常用指令

查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...