You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Databricks SQL Notebook中统计表列数(information_schema.columns失效)

在Databricks SQL Notebook中统计表列数的解决方案

你遇到的问题是因为information_schema.columns需要同时指定数据库名(table_schema)和表名才能准确匹配,只过滤table_name会导致查询范围不准确,所以无法返回正确列数。

修正后的查询语句

select 'ett.data_beat' as Table_Name
       ,max(_createTime_) as Last_Create_Date
       ,max(_upt_) as Last_Update_Date 
       ,(select count(*)
          from information_schema.columns
          where table_schema = 'ett'
            and table_name = 'data_beat'
        ) as Columns_Count
       ,(select count(*)
          from data_lineage.field_dependencies
          where source like 'ett.data_beat%'
        ) as Count_to_L1
from ett.data_beat

关键修改点

  • 在information_schema.columns的子查询中添加table_schema = 'ett',明确指定表所属的数据库
  • 将Table_Name字段的值从'data_beat'改为'ett.data_beat',匹配你期望的结果格式

这样就能正确统计目标表的列数,同时返回你需要的所有字段。

内容的提问来源于stack exchange,提问作者Marina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 13:15:00