首页 > 数据库技术 > 详细

查询表名及列名长度超过一定长度的SQL

时间:2018-12-04 16:23:43      阅读:248      评论:0      收藏:0      [点我收藏+]
apple=# select * from (select a.relname, char_length(a.relname) as tb_name_length, b.attname, char_length(b.attname) as att_name_length, d.typname, b.attlen, b.attnum from pg_class a, pg_attribute b ,pg_tables c , pg_type d where b.attrelid = a.oid and b.attnum > 0  and c.schemaname = ‘public‘ and a.relname = c.tablename and b.atttypid = d.oid ) as d where d.tb_name_length > 10 or att_name_length > 10;
        relname        | tb_name_length |      attname       | att_name_length |  typname  | attlen | attnum
-----------------------+----------------+--------------------+-----------------+-----------+--------+--------
 test_0001              |              8 | datatypename       |              12 | varchar   |     -1 |      2
 test_0001              |              8 | startuptime        |              11 | timestamp |      8 |      5

 

暂时这样写,后续修改从pg_namespace获取schema为public的表:

 

select * from (select a.relname, char_length(a.relname) as tb_name_length, b.attname, char_length(b.attname) as att_name_length, d.typname, b.attlen, b.attnum from pg_class a, pg_attribute b ,pg_namespace c , pg_type d where b.attrelid = a.oid and b.attnum > 0  and c.nspname = ‘public‘ and a.relnamespace = c.oid and b.atttypid = d.oid ) as d where d.tb_name_length > 10 or att_name_length > 10;

 

查询表名及列名长度超过一定长度的SQL

原文:https://www.cnblogs.com/kuang17/p/10064511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!