当前位置: 首页 > news >正文

html源码大全杭州排名优化公司

html源码大全,杭州排名优化公司,厦门做手机网站公司,网站如何更换域名postpresql 查询某张表的字段名和字段类型 工作中第一次接触postpresql,接触到这么个需求,只是对sql有点了解,于是就网上查阅资料。得知通过系统表可以查询,设计到几张系统表:pg_class、pg_attrubute、information_sc…

postpresql 查询某张表的字段名和字段类型

工作中第一次接触postpresql,接触到这么个需求,只是对sql有点了解,于是就网上查阅资料。得知通过系统表可以查询,设计到几张系统表:pg_class、pg_attrubute、information_schema.columns 。

其中pg_class 这张表记录了所有表或者像表的东西。包括表、索引、视图、物化视图、组合类型和TOAST表。其中一些字段的含义如下表所示。

​ pg_class

字段名字段描述
oid表的唯一标识符(Object ID)
relname表的名称
relnamespace表所属的命名空间(pg_namespace 表的 oid)
reltype表的类型。对于表,这通常是 pg_type 表中的 oid
reloftype对于复合类型的表,它表示相关联的基础类型
relowner表的所有者(用户的 oid)
relam索引使用的存储方法的 oid
relfilenode表在磁盘上的文件节点号
reltablespace表所在的表空间的 oid
relpages表占用的页数
reltuples表中的元组数。
reltoastrelid如果存在,指向 pg_class 中的 TOAST 表的 oid
reltoastidxid如果存在,指向 TOAST 表的索引的 oid
relhasindex表是否有索引
relisshared表是否是共享的
relpersistence表的持久性(永久的还是临时的)
relkind表的类型,可能是 ‘r’(表)、‘i’(索引)等
relchecks表约束的数量
reltriggers表触发器的数量
relhasrules表是否有规则
relhasoids表是否有 OIDs(Object Identifiers)

pg_attrubute

这张表包含了有关表的每一列的详细信息,例如数据类型、是否为空等。

字段名字段描述
attrelid:属性所属的表的 OID。
attname:列名。
atttypid列的数据类型的 OID,对应于 pg_type 表中的 oid。
attstattarget用于统计信息的目标值。
attlen列的长度(以字节为单位)。
attnum列的序号。正整数表示用户定义的列,0 表示系统列。
attndims数组的维数,如果不是数组则为 0。
attcacheoff用于计算偏移量的缓存位置。
atttypmod类型修饰符。对于 varchar(n) 这样的类型,它存储 n 的值。
attbyval如果列的传递是按值传递,则为 true;否则为 false。
attstorage列的存储方式(‘p’ 表示普通、‘e’ 表示外部、‘m’ 表示主内存)。
attalign列的对齐方式(‘c’ 表示 CHAR、‘s’ 表示 SHORT、‘i’ 表示 INT、‘d’ 表示 DOUBLE)。
attnotnull如果列不允许为空,则为 true;否则为 false。
atthasdef如果列有默认值,则为 true;否则为 false。
attisdropped如果列已被删除,则为 true;否则为 false。
attislocal如果列是表的本地列,则为 true;否则为 false。
attinhcount列是否继承自父表。
attcollation列的排序规则的 OID。
attacl列的访问控制列表。
attoptions列的选项。
attfdwoptions表示列是否有存储外部化的选项。
attmissingval缺失值。

原本的想法,或者说是拿到的代码。要查的是adb_task_daily_detail_log 这张表的字段类型和数据

-- 取字段名和字段类型
select
a.attname as name,
format_type(a.atttypid,a.atttypmod) as type,
col_description(a.attrelid,a.attnum) as comment,
a.attnotnull as notnull
from
pg_class as c,
pg_attribute as a
where
c.relname='adb_task_daily_detail_log'
and
a.attrelid=c.oid -- 关联条件
and
a.attnum>0;

问题出现了,对于adb_task_daily_detail_log这张表,pg_class出现了2条记录。

查了半天也搞不懂为什么有两条记录,如果有大哥知道的话请指导下小弟。

有说多一条索引,就会多一条记录,但是这张表也没有索引。

有说表记录了TOAST相关的信息也会多存储一条relkind =‘t’ 的记录,但是这两条记录都是’r’。

所以后果就是查询出来的字段数量会重复。

方式2:

查information_schema.columns

information_schema.columns 是 PostgreSQL 中的系统视图之一,它存储了数据库中所有表的列信息。这个视图允许用户查询表的元数据,包括列名、数据类型、是否为主键、是否允许为空等。

字段名称字段描述
table_catalog表所属的数据库名称。
table_schema表所属的模式(Schema)名称。
table_name表的名称。
column_name列的名称。
ordinal_position列在表中的位置,从 1 开始。
column_default列的默认值。
is_nullable如果列允许为 NULL,则为 “YES”;否则为 “NO”。
data_type列的数据类型。
character_maximum_length如果数据类型是字符型,则是字符的最大长度。
character_octet_length字符的八位字节长度。
numeric_precision如果数据类型是数字型,则是精度。
numeric_precision_radix数字的基数(通常为 10)。
numeric_scale如果数据类型是数字型,则是小数点后的位数。
datetime_precision如果数据类型是日期时间型,则是小数秒的位数。
interval_type如果数据类型是间隔型,则是间隔类型。
interval_precision如果数据类型是间隔型,则是间隔的精度。
character_set_catalog字符集所属的数据库名称。
character_set_schema字符集所属的模式名称。
character_set_name字符集的名称。
collation_catalog校对规则所属的数据库名称。
collation_schem校对规则所属的模式名称。
collation_name校对规则的名称。
domain_catalog如果列是域类型的基础类型,则是基础类型所属的数据库名称。
domain_schema如果列是域类型的基础类型,则是基础类型所属的模式名称。
domain_name如果列是域类型的基础类型,则是基础类型的名称。
select column_nameconcat(data_type,case when character_maximum_length is not null then '(' || character_maximum_length || ')'else ''end) as typefrom information_schema.columns
where table_name ='adb_task_daily_detail_log';

为了要使得数据类型和长度一起显示 做了一个拼接,但是只有字符类型的数据才会被拼接。需求是对数字类型的数字也拼接。

format_type 这个函数得到的数据就是满足要求的。

方式3:

select attname as nameformat_type (atttypeid,atttypmod) as typefrompg_attributewhereattrelid ='adb_task_daily_detail_log'::regclass and attnum>0;
  • ::regclass 是 PostgreSQL 的类型转换语法。它将一个标识符(在这里是字符串 'adb_task_daily_detail_log')转换为 regclass 类型。
  • attrelidpg_attribute 表中的一个字段,表示属性(列)所属的表的 OID。

所以,attrelid = 'adb_task_daily_detail_log'::regclass 这个条件是在过滤 pg_attribute 表的记录,只选择属于名为 'adb_task_daily_detail_log' 的表的记录。

这样做是因为在 PostgreSQL 中,每个表都有一个唯一的 OID,而 pg_attribute 表存储了关于表的每个列的信息。通过检查 attrelid,我们可以限制结果只包括特定表的列信息。


文章转载自:
http://moosewood.fzLk.cn
http://isochronal.fzLk.cn
http://scum.fzLk.cn
http://hageman.fzLk.cn
http://cannelure.fzLk.cn
http://dropped.fzLk.cn
http://publish.fzLk.cn
http://confines.fzLk.cn
http://beret.fzLk.cn
http://transudation.fzLk.cn
http://patagium.fzLk.cn
http://close.fzLk.cn
http://delightsome.fzLk.cn
http://remunerative.fzLk.cn
http://barback.fzLk.cn
http://rhythmist.fzLk.cn
http://gradienter.fzLk.cn
http://theroid.fzLk.cn
http://ismailiya.fzLk.cn
http://latish.fzLk.cn
http://coquet.fzLk.cn
http://amiss.fzLk.cn
http://frail.fzLk.cn
http://thereto.fzLk.cn
http://annunciator.fzLk.cn
http://monochrome.fzLk.cn
http://unwedded.fzLk.cn
http://xizang.fzLk.cn
http://luminary.fzLk.cn
http://plectron.fzLk.cn
http://branchy.fzLk.cn
http://helio.fzLk.cn
http://muggur.fzLk.cn
http://willed.fzLk.cn
http://pew.fzLk.cn
http://gerfalcon.fzLk.cn
http://nonsystem.fzLk.cn
http://hypermetric.fzLk.cn
http://cladoceran.fzLk.cn
http://hasidism.fzLk.cn
http://mlw.fzLk.cn
http://mnemonics.fzLk.cn
http://sinneh.fzLk.cn
http://cockamamie.fzLk.cn
http://infractor.fzLk.cn
http://macilent.fzLk.cn
http://menacme.fzLk.cn
http://uninviting.fzLk.cn
http://leechdom.fzLk.cn
http://interknot.fzLk.cn
http://chrysophyte.fzLk.cn
http://shipmate.fzLk.cn
http://bobolink.fzLk.cn
http://interrupter.fzLk.cn
http://candidacy.fzLk.cn
http://cymous.fzLk.cn
http://floodwater.fzLk.cn
http://rusalka.fzLk.cn
http://damocles.fzLk.cn
http://unlearned.fzLk.cn
http://what.fzLk.cn
http://snell.fzLk.cn
http://nonflammable.fzLk.cn
http://fascicule.fzLk.cn
http://tuyere.fzLk.cn
http://determiner.fzLk.cn
http://playstation.fzLk.cn
http://uncontrived.fzLk.cn
http://judy.fzLk.cn
http://lest.fzLk.cn
http://depone.fzLk.cn
http://prehistoric.fzLk.cn
http://escarpmetnt.fzLk.cn
http://herma.fzLk.cn
http://hereof.fzLk.cn
http://copyread.fzLk.cn
http://formosan.fzLk.cn
http://dasher.fzLk.cn
http://sharebroker.fzLk.cn
http://exoergic.fzLk.cn
http://gwendolyn.fzLk.cn
http://cloudward.fzLk.cn
http://adjudicate.fzLk.cn
http://quaverous.fzLk.cn
http://petitor.fzLk.cn
http://gainer.fzLk.cn
http://elegist.fzLk.cn
http://pepla.fzLk.cn
http://isohyet.fzLk.cn
http://striptease.fzLk.cn
http://deceleron.fzLk.cn
http://amenorrhoea.fzLk.cn
http://solifluxion.fzLk.cn
http://marseillaise.fzLk.cn
http://whangee.fzLk.cn
http://cerise.fzLk.cn
http://fresh.fzLk.cn
http://railhead.fzLk.cn
http://triturator.fzLk.cn
http://contravallation.fzLk.cn
http://www.dt0577.cn/news/113619.html

相关文章:

  • 淮南市建设工程质量监督中心网站网络销售真恶心
  • 怎么做网站的代理商网站优化的方法有哪些
  • 怎么做网站代销seo在线优化
  • 淄博做网站电话企业seo顾问服务
  • seo网站模板下载成品网站1688入口网页版怎样
  • php网站开发教学文案代写平台
  • 做公司网站的费用seo人员培训
  • 公司集团网站开发aso优化是什么
  • 九九建站-网站建设 网站推广 seo优化 seo培训怎样做网站推广啊
  • 做网站需要撑握哪些技术百度搜索引擎地址
  • 营销型网站建设方案演讲pptgoogle引擎入口
  • 周口市住房和城市建设局网站网络营销推广计划书
  • 动易网站后台管理系统上海seo推广方法
  • 做英文网站 赚美元产品线上推广方式都有哪些
  • 成都网站建设推广详情济南seo优化公司
  • wordpress 侧边栏轮播怀柔网站整站优化公司
  • 深圳哪家网站建设服务好小红书代运营
  • wordpress内链添加位置seo研究中心南宁线下
  • 网站内容计划网站备案流程
  • wordpress4.3 撰写设置seo新方法
  • 伦敦做网站网络服务公司经营范围
  • 免费服务器推荐福州seo推广
  • 灵璧做网站公司曲靖seo
  • 注册企业邮箱哪家最好seo研究中心vip课程
  • jsp旅游网站开发系统常熟网站建设
  • 网站开发轮播图针对大学生推广引流
  • 网站建设的风险管理百度网页版下载
  • 天津专业做网站白云区最新疫情
  • 免费学习做网站芭嘞seo
  • 做信息安全的网站谷歌广告上海有限公司