postgreSQL-如何查数据库表、字段以及字段类型、注释等信息?
2013-12-03 11:20
716 查看
之前从网上也搜索了一些关于postgreSQL的系统表含义以及如何查表相关信息,但是都没有一个完整的内容,所以自己将找到的一些内容作了下整合,大家可以根据自己需要再对sql进行调整。
--1.查询对象字段、注释和字段类型 select t.schemaname ,c.relname object_name ,d.description object_comment --,c.reltuples count --,c.relkind object_type --r = 普通表,i = 索引,S = 序列,v = 视图, c = 复合类型,s = 特殊,t = TOAST表 --,c.relhaspkey primary_key --f:假,t-:真 ,a.attname column_name ,db.description column_comment ,s.attrnums distributed_column --,case when s.attrnums is not null then 'is distributed key' end distributed_column --,a.attnum column_seq ,case p.typname when 'int8' then 'bigint' when 'int4' then 'integer' when 'int2' then 'smallint' when 'timestamp' then 'timestamp without time zone' when 'date' then 'date' when 'varchar' then 'character varying('||a.atttypmod - 4||')' when 'numeric' then 'numeric('||(a.atttypmod - 4) / 65536||','||(atttypmod - 4) % 65536||')' end column_type ,at.adsrc AS column_default ,CASE WHEN a.attnotnull THEN 'not null' ELSE '' END AS column_not_null --,p.typname --,p.typlen --,a.atttypmod - 4 as column_length from pg_tables t inner join pg_class c on t.tablename=c.relname left join pg_description d on c.oid=d.objoid and d.objsubid=0 left join pg_description db on c.oid=db.objoid and db.objsubid>0 left join pg_attribute a on c.oid=a.attrelid and db.objsubid=a.attnum left join ( select a.attrnums[i.i] attrnums,b.attname,a.localoid from gp_distribution_policy a, (select generate_series(1,10)) i(i), --预计表分布键的个数为10个 pg_attribute b where a.attrnums[i.i] is not null and a.localoid=b.attrelid and a.attrnums[i.i]=b.attnum ) s on c.oid=s.localoid and a.attnum=s.attrnums left join pg_type p on a.atttypid=p.oid left join pg_attrdef at on c.oid=at.adrelid and a.attnum=at.adnum where upper(c.relname) = upper('bas_add_sub_rep') --表名 order by a.attnum;
相关文章推荐
- 根据数据库表名查询该表字段名、字段类型、以及注释
- 根据数据库表名查询该表字段名、字段类型、以及注释
- 针对不同数据库,获取当前用户所有有权限查看的表,以及表的创建时间、更新时间、注释等信息,表中字段的相关信息(包含分页实现)
- Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库 自定义日志记录功能,按日记录,很方便 C#常量和字段以及各种方法的语法总结 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法 asp.net webapi 自定义身份验证
- 关于在VISIO中进行数据库建模时如何显示字段类型,以及注释的
- mysql查询某个数据库中某个表的所有字段名、字段类型和注释
- Sqlserver获取所有数据库名,表信息,字段信息,主键信息,以及表结构等。
- sharepoint各种字段类型如何读取以及赋值...
- MySQL数据库中字段设置了zerofill,页面上显示时整数前仍带有0以及如何查询字段注释
- ActiveAndroid 管理数据库以及ActiveAndroid 如何管理boolean类型
- SQL Server 2008获取一个表的字段,类型,长度,是否主键,是否为空,注释等信息
- 【Hibernate】Hibernate中查询表名、字段名以及字段类型等信息
- oracle 根据表名查询字段的详细信息 字段类型 注释
- 获取通过sql查询数据库的表,字段,主键,自增,字段类型等信息。
- 【Oracle】查询字段的长度、类型、精度、注释等信息
- MySQL-修改字段类型、设置默认值,以及添加注释
- 如何对数据库中的表以及表中的字段进行重命名
- 如何获取SQL Server所有的数据库名、表名、字段名及字段类型?
- sqlserver数据库创建视图时如何改变字段类型以及查询视图详细内容
- PostgreSQL获取所有表名、字段名、字段类型、注释