代码编织梦想

select
	table_catalog ,
	table_schema ,
	table_name ,
	ordinal_position as sort,
	column_name ,
	data_type as TypeName,
	(case
		when (is_nullable = 'no' and contype !='p' ) then '1'
		else null
	end) as is_required,
	(case
		when contype = 'p' then '1'
		else '0'
	end) as is_pk,
	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 position('nextval' in column_default)>0 then 1
		else 0
	end) as is_increment,
	c.DeText as column_comment,
	c.typname as column_type,
	ordinal_position
from
	information_schema.columns
	left join (select
		datname,pg_get_userbyid(relowner) AS tableowner,nspname,relname,attname
	                , col_description(pg_attr.attrelid, pg_attr.attnum) as DeText,typname,pg_cons.contype
	from
		pg_class
	left join pg_attribute pg_attr on
		pg_attr.attrelid = pg_class.oid
	left join pg_description pg_desc on
		pg_desc.objoid = pg_attr.attrelid
		and pg_desc.objsubid = pg_attr.attnum
	left join pg_namespace pg_ns on
		pg_ns."oid" = pg_class.relnamespace
	left join pg_database on relowner = datdba
	left join pg_type on pg_attr.atttypid = pg_type."oid"
	left join (select pg_con.*,unnest(conkey) conkey_new from pg_constraint pg_con)  pg_cons on
		pg_attr.attrelid = pg_class.oid
		and pg_attr.attnum = pg_cons.conkey_new and pg_cons.conrelid = pg_class.oid
	where
		pg_attr.attnum>0
		and pg_attr.attrelid = pg_class.oid
		 and nspname='public'
		) c
	on  table_schema = nspname and table_name = relname and column_name = attname
where table_schema='public' and c.DeText like '%状态%'
order by table_name

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq56477643/article/details/129425154

postgresql 修改表字段_postgresql 字段sql语句 更改表名-爱代码爱编程

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/sq8706/article/details/7077148 1.更改表名 alter table 表名 rename to 新表名 2.更改字段名 alter table 表名 re

postgre 查询注释_postgresql 实现获取所有表名,字段名,字段类型,注释-爱代码爱编程

获取表名及注释: select relname as tabname,cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c where relkind = 'r' and relname not like 'pg_%' and reln

好好的系统,为什么要分库分表?-爱代码爱编程

不急于上手实战 ShardingSphere 框架,先来复习下分库分表的基础概念,技术名词大多晦涩难懂,不要死记硬背理解最重要,当你捅破那层窗户纸,发现其实它也就那么回事。 什么是分库分表 分库分表是在海量数据下,由于单库、表数据量过大,导致数据库性能持续下降的问题,演变出的技术方案。 分库分表是由分库和分表这两个独立概念组成的,只不过通常分库与分表

postgresql 不建议使用独立表空间-爱代码爱编程

  有Oracle使用经历的用户都会认为表空间非常重要,但对PostgreSQL中的表空间却知之甚少。本文将解释它们是什么,何时有用以及是否应该使用它们。 什么是表空间 本质上,PostgreSQL中的表空间是一个包含数据文件的目录。这些数据文件是表、序列、索引和物化视图等对象背后的存储空间。在PostgreSQL中,每个这样的对象都有自己的数据

timescaledb 超表-爱代码爱编程

关于超表 超表(hypertable)是具有特殊功能的PostgreSQL表,可以很容易地处理时间序列数据。与它们交互就像与普通PostgreSQL表交互一样,但在幕后,超表会自动按时间将数据划分为块。 在Timescal

postgresql 使用记录-爱代码爱编程

1. 重命名数据库时,报错:“其他用户正在使用数据库...” 报错如下: ERROR: 错误: 其他用户正在使用数据库 "<DBname>" DETAIL: 那里有1个其它会话正在使用数据库. SQL 状态: 55006 解决方法: SELECT pg_terminate_backend(pg_stat_activity

如何在windows 10中安装postgresql 15-爱代码爱编程

PostgreSQL是一个强大的开源对象关系数据库系统,经过35年的积极开发,在可靠性、功能健壮性和性能方面赢得了很高的声誉。 通过官方文档可以找到大量的信息来描述如何安装和使用PostgreSQL。开源社区为熟悉Post

第01章-爱代码爱编程

1. 为什么要使用数据库 持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用。大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到硬盘上加以”固化”,而持久化的实现过程大多通过各种

mysql 事务_mysql readview db_trx_id 大于read view 最大值 咋办-爱代码爱编程

文章目录 1.MySQL事务的四大特性2.ACID的实现2.1 持久性2.2 原子性2.3 隔离性2.3.1 脏读,不可重复读,幻读(1)脏读(2)不可重复读(3)幻读 2.3.2 事务的隔离级别读