栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

计算PostgreSQL中列类型的大小

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

计算PostgreSQL中列类型的大小

pg中只有少数类型具有固定长度-几乎所有类型都是varlena类型-它具有动态长度。您可以检查类似的查询

 postgres=# select typlen from pg_type where oid = 'int'::regtype::oid;  typlen  --------       4 (1 row) postgres=# select attlen from pg_attribute where attrelid = 'x'::regclass and attname = 'a';  attlen  --------       4 (1 row)

当结果不是-1时,类型没有固定长度

对于varlena类型,请使用pg_column_size函数:

postgres=# df *size*  List of functions   Schema   |          Name          | Result data type | Argument data types |  Type  ------------+------------------------+------------------+---------------------+-------- pg_catalog | pg_column_size         | integer          | "any"    | normal pg_catalog | pg_database_size       | bigint| name     | normal pg_catalog | pg_database_size       | bigint| oid      | normal pg_catalog | pg_indexes_size        | bigint| regclass | normal pg_catalog | pg_relation_size       | bigint| regclass | normal pg_catalog | pg_relation_size       | bigint| regclass, text      | normal pg_catalog | pg_size_pretty         | text  | bigint   | normal pg_catalog | pg_size_pretty         | text  | numeric  | normal pg_catalog | pg_table_size          | bigint| regclass | normal pg_catalog | pg_tablespace_size     | bigint| name     | normal pg_catalog | pg_tablespace_size     | bigint| oid      | normal pg_catalog | pg_total_relation_size | bigint| regclass | normal(12 rows) postgres=# select pg_column_size('Hello');  pg_column_size  ----------------          6 (1 row) postgres=# select pg_column_size(10);  pg_column_size  ----------------    4 (1 row) postgres=# select pg_column_size(now());  pg_column_size  ----------------    8


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400245.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号