postgresql数据库中,查询一个字段允许的最大长度的SQL语句怎么写?

 我来答
全糖麦麦eh
2011-06-24 · TA获得超过136个赞
知道答主
回答量:94
采纳率:0%
帮助的人:55.4万
展开全部
select
relname as 表名,
attname as 列名,
attnum as 列号,
case typname
when '_bpchar' then 'char'
when '_varchar' then 'varchar'
when '_date' then 'date'
when '_float8' then 'float8'
when '_int4' then 'integer'
when '_interval' then 'interval'
when '_numeric' then 'numeric'
when '_float4' then 'float4'
when '_int2' then 'smallint'
when '_text' then 'text'
when '_time' then 'time'
when '_timestamp' then 'timestamp'
end as 类型,
case typname
when '_bpchar' then atttypmod - 4
when '_varchar' then atttypmod - 4
when '_numeric' then (atttypmod - 4) / 65536
else attlen
end as 长度,
case typname
when '_numeric' then (atttypmod - 4) % 65536
else 0
end as 小数

from pg_stat_user_tables as a,
pg_attribute as b,
pg_type as c
where schemaname='u1'
and relname='t1'
and a.relid=b.attrelid
and b.attnum>0
and b.atttypid=c.typelem
and substr(typname,1,1)='_'
order by schemaname,relname,attnum;

where条件的地方 自己适当删减
摆渡浮桥
2011-06-24 · TA获得超过3629个赞
知道大有可为答主
回答量:1610
采纳率:100%
帮助的人:2215万
展开全部
对于character类型和character varying类型的字段,也可以用一下语句查询。
SELECT
attname as "name", typname as "type", atttypmod - 4 as "size"
FROM
pg_class AS a
LEFT OUTER JOIN pg_attribute AS b ON (b.attrelid = a.oid)
LEFT OUTER JOIN pg_type AS c ON (b.atttypid = c.oid)
where a.relname = '<tablename>' and attname='<fieldname>'
and b.attstattarget = -1
order by attnum;
希望对你有所帮助。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式