当前位置: 首页 > 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;打开开始菜单中的“所有应…...

Docker 离线安装指南

参考文章 1、确认操作系统类型及内核版本 Docker依赖于Linux内核的一些特性&#xff0c;不同版本的Docker对内核版本有不同要求。例如&#xff0c;Docker 17.06及之后的版本通常需要Linux内核3.10及以上版本&#xff0c;Docker17.09及更高版本对应Linux内核4.9.x及更高版本。…...

装饰模式(Decorator Pattern)重构java邮件发奖系统实战

前言 现在我们有个如下的需求&#xff0c;设计一个邮件发奖的小系统&#xff0c; 需求 1.数据验证 → 2. 敏感信息加密 → 3. 日志记录 → 4. 实际发送邮件 装饰器模式&#xff08;Decorator Pattern&#xff09;允许向一个现有的对象添加新的功能&#xff0c;同时又不改变其…...

Flask RESTful 示例

目录 1. 环境准备2. 安装依赖3. 修改main.py4. 运行应用5. API使用示例获取所有任务获取单个任务创建新任务更新任务删除任务 中文乱码问题&#xff1a; 下面创建一个简单的Flask RESTful API示例。首先&#xff0c;我们需要创建环境&#xff0c;安装必要的依赖&#xff0c;然后…...

线程与协程

1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指&#xff1a;像函数调用/返回一样轻量地完成任务切换。 举例说明&#xff1a; 当你在程序中写一个函数调用&#xff1a; funcA() 然后 funcA 执行完后返回&…...

ffmpeg(四):滤镜命令

FFmpeg 的滤镜命令是用于音视频处理中的强大工具&#xff0c;可以完成剪裁、缩放、加水印、调色、合成、旋转、模糊、叠加字幕等复杂的操作。其核心语法格式一般如下&#xff1a; ffmpeg -i input.mp4 -vf "滤镜参数" output.mp4或者带音频滤镜&#xff1a; ffmpeg…...

Axios请求超时重发机制

Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式&#xff1a; 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...

c#开发AI模型对话

AI模型 前面已经介绍了一般AI模型本地部署&#xff0c;直接调用现成的模型数据。这里主要讲述讲接口集成到我们自己的程序中使用方式。 微软提供了ML.NET来开发和使用AI模型&#xff0c;但是目前国内可能使用不多&#xff0c;至少实践例子很少看见。开发训练模型就不介绍了&am…...

AspectJ 在 Android 中的完整使用指南

一、环境配置&#xff08;Gradle 7.0 适配&#xff09; 1. 项目级 build.gradle // 注意&#xff1a;沪江插件已停更&#xff0c;推荐官方兼容方案 buildscript {dependencies {classpath org.aspectj:aspectjtools:1.9.9.1 // AspectJ 工具} } 2. 模块级 build.gradle plu…...

【安全篇】金刚不坏之身:整合 Spring Security + JWT 实现无状态认证与授权

摘要 本文是《Spring Boot 实战派》系列的第四篇。我们将直面所有 Web 应用都无法回避的核心问题&#xff1a;安全。文章将详细阐述认证&#xff08;Authentication) 与授权&#xff08;Authorization的核心概念&#xff0c;对比传统 Session-Cookie 与现代 JWT&#xff08;JS…...

macOS 终端智能代理检测

&#x1f9e0; 终端智能代理检测&#xff1a;自动判断是否需要设置代理访问 GitHub 在开发中&#xff0c;使用 GitHub 是非常常见的需求。但有时候我们会发现某些命令失败、插件无法更新&#xff0c;例如&#xff1a; fatal: unable to access https://github.com/ohmyzsh/oh…...