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 relname not like ‘sql_%‘ order by relname

过滤掉分表:

加条件 and relchecks=0 即可

获取字段名、类型、注释、是否为空:
SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull   
FROM pg_class as c,pg_attribute as a where c.relname = ‘表名‘ and a.attrelid = c.oid and a.attnum>0

原文地址:https://www.cnblogs.com/firstdream/p/9310935.html

时间: 2024-10-05 05:23:50

postgresql 获取所有表名、字段名、字段类型、注释的相关文章

mysql获取某个表的所有属性名及其数据

MYSQL类实现从数据库相应的表中获取所有属性及其数据,数据为元组类型.返回结果存放在字典中 import pymysql class MYSQL: def __init__(self): pass def __del__(self): self._cursor.close() self._connect.close() def connectDB(self): """ 连接数据库 :return: """ try: self._connect

[转]ef获取某个表中的部分字段值

我有个新闻表 id,title,body,createtime,author,click 使用ef4.1 仅仅读取 id,title,createtime 并显示在页面上. public static List<NewInfo> GetHotNews() { List<NewInfo> list; list = (from n in db.NewInfoes where n.IsTop == 1 orderby n.PublishTime descending select new

java获取form表单里的字段和文件流

Map map=new HashMap(); boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { // 文件上传 // 用stream api处理,提高性能 // System.err.println("file upload request..."); ServletFileUpload upload = new ServletFileUpload(); Fil

PostgreSQL获取table名,字段名

PostgreSQL获取数据库中所有table名: SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' ORDER BY tablename; PostgreSQL获取数据库中所有table名及table的注解信息: SELECT tablename, obj_description(relfilenode, 'pg_class') FROM pg_tables

SQL语句获取所有数据库名、表名、字段名、表字段长度

引自:http://www.2cto.com/database/201209/155178.html 获取数据库中所有的表 SELECT SysObjects.name AS Tablename FROM sysobjects WHERE xtype = 'U' 获取数据库中所有表的列名 SELECT SysColumns.name AS Columnsname, SysObjects.name AS Tablename FROM SysObjects, SysColumns WHERE Sys

如何使用sqlalchemy获取表的主键、以及每一个字段名

使用sqlalchemy获取到的结果只包含数据,不包含字段,那么我们如何获取到对应字段呢?以及如何获取某张表的主键呢? from sqlalchemy.ext.automap import automap_base from sqlalchemy.orm import sessionmaker from sqlalchemy import MetaData, inspect, create_engine engine = create_engine("postgresql://postgres:

MySQL获取Schema表名和字段信息

MySQL获取Schema表名和字段信息 获取表名 select TABLE_NAME,TABLE_TYPE,ENGINE,TABLE_ROWS,TABLE_COMMENT,CREATE_TIME,UPDATE_TIME, CHECK_TIME from information_schema.TABLES where TABLE_SCHEMA='t_shop' ; 获取字段名 select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NUL

Oracle中使用游标获取指定数据表的所有字段名对应的字符串

操作步骤:打开PLSQL Developer后,直接执行下面的语句就可以出来 --Oracle中使用游标获取指定数据表的所有字段名对应的字符串 declare mytablename VARCHAR(255):='STAFFDOC'; --定义要查询的数据表名变量,STAFFDOC为我测试用的数据表名,请修改成您的数据库中的对应数据表名字mystring NVARCHAR2(4000):=''; --定义要输出的字符串变量 cursor mycursor is --定义游标          s

SQLServer2005,2000获取表结构:字段名、类型、长度、主键、非空、注释

SQLServer 2005 SELECT d.name N'TableName', d.xtype N'TableType', a.colorder N'ColumnIndex', a.name N'ColumnName', (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '1'else '0' end) N'IdnetityFG', (case when (SELECT count(*) FROM sysobjects