首页 > 数据库 >postgresql用sql查询表结构

postgresql用sql查询表结构

时间:2023-01-03 21:47:18浏览次数:41  
标签:postgresql attnum 查询 attrelid sql type pg

  

查询sql如下:

SELECT 
a.attname AS field,
t.typname AS type,
CASE WHEN t.typlen = -1 THEN a.atttypmod - 4 ELSE t.typlen::integer END AS lengthvar,
case a.attnotnull when 't' then 'NO' else 'YES' end AS notnull,
b.description AS comment
FROM pg_class c,
pg_attribute a
LEFT OUTER JOIN pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid,
pg_type t
WHERE c.relname = 'data_air_site_day'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY a.attnum;

 

标签:postgresql,attnum,查询,attrelid,sql,type,pg
From: https://www.cnblogs.com/tiandi/p/17023441.html

相关文章

  • SQL优化案例8(DM数据库SQL分页案例)
    DM一哥们找我优化条分页的SQL语句,结果集很小返回99行数据,废话不说安排一下。原始SQL语句如下,保密要求,给真实的表名换了别名:SELECTcount(*)FROM(SELECTTMP.*,......
  • [MySQL] 索引的使用、SQL语句优化策略
    目录索引什么是索引索引的创建与删除创建索引删除索引索引的使用使用explain分析SQL语句最佳左前缀索引覆盖避免对索引列进行额外运算SQL语句优化小表驱动大表索引什么是......
  • Mysql 8 修改root密码
    sudomysql-uroot-p#使用sudo之后mysql密码为空即可登陆updateusersetauthentication_string=''whereuser='root';flushprivileges;ALTERUSER'root'@'local......
  • k8s运行单实例mysql
    namespacemysql-ns.yamlapiVersion:v1kind:Namespacemetadata:labels:kubernetes.io/metadata.name:wgs-mysqlname:wgs-mysql创建ns#kubectlapply......
  • [clickhouse]同步MySQL
    前言clickhouse的查询速度非常快,而且兼容大部分MySQL的sql语法,因此一般将clickhouse作为MySQL的读库。本文提供两种clickhouse同步MySQL的方式clickhouse版本:21.2.4.6......
  • 软件开发入门教程网之MySQL 删除数据库
       ......
  • Mysql主从同步配置
    一、主数据库的配置1.my.cnf(Linux)/my.ini(Windows)在配置文件参数选项[mysqld]下面添加如下内容log_bin=mysql-binserver_id=1innodb_flush_log_at_trx_commit=......
  • mysql函数笔记
    count(*)计数avg()求一列的平均数distinct(q.device_id)对某一列去重,一般与count()连用count(question_id)/count(distinct(q.device_id))if(age>=25,'25岁及以上','25......
  • 超图iServer rest服务之半径查询(axios)
    超图iServer服务使用过程,涉及到图层数据相关查询,提供的是rest服务,通过传入对应的参数,返回数据的查询结果。iServer中查询feature的服务,对应是featureResults查询,可以使用超......
  • mysql 查询上月数据PERIOD_DIFF
    select*fromtable1wherePERIOD_DIFF(date_format(now(),'%Y%m'),date_format(fieldname,'%Y%m'))=1说明:查询table1的fieldname为上月的数据。PERIOD_DIFF()函......