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

求助:Teradata大型CTE子查询转BigQuery实现方案

Teradata to BigQuery Conversion for Your Row-Numbered Table Query

First, let's map Teradata's system metadata structure to BigQuery's equivalent. Teradata's dbc.tables (which lists all tables across the system) lines up with BigQuery's INFORMATION_SCHEMA.TABLES view—this is the standard, SQL-compliant way to access table metadata in BigQuery.

Your original Teradata query:

select row_number() over (order by tablename) from dbc.tables

Here's the direct BigQuery translation:

SELECT ROW_NUMBER() OVER (ORDER BY table_name)
FROM INFORMATION_SCHEMA.TABLES

Quick Details to Keep in Mind:

  • BigQuery uses table_name (lowercase, underscore-separated) instead of Teradata's tablename—this follows standard SQL naming conventions for system views that BigQuery enforces.
  • If you need to narrow results to a specific project or dataset (since INFORMATION_SCHEMA.TABLES defaults to all datasets you have access to), add a filter like this:
    SELECT ROW_NUMBER() OVER (ORDER BY table_name)
    FROM INFORMATION_SCHEMA.TABLES
    WHERE table_catalog = 'your_project_id'
      AND table_schema = 'your_dataset_id'
    
  • For your cross join use case: BigQuery supports CROSS JOIN exactly like Teradata does. Just make sure both subqueries have clear aliases to avoid column name clashes, for example:
    WITH larger_subquery AS (
      -- Your existing larger subquery logic goes here
      SELECT ...
    ),
    numbered_table_list AS (
      SELECT ROW_NUMBER() OVER (ORDER BY table_name) AS table_row_num, table_name
      FROM INFORMATION_SCHEMA.TABLES
    )
    SELECT *
    FROM larger_subquery
    CROSS JOIN numbered_table_list
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:04:03