expect_table_column_count_to_equal_other_table

Feb 24, 2026

·

5

min read

Schema

·

dbt-expectations

·

Model,Seed,Source

How it Works

The expect_table_column_count_to_equal_other_table test from the dbt-expectations package validates that two tables have the same number of columns. This is useful for ensuring that a transformed model retains the same schema width as a source or reference table, guarding against silent column additions or removals.

Steps and Conditions

  1. Comparison Model: Specify the reference model using compare_model.

  2. Execution: The column counts of both tables are retrieved and compared.

  3. Outcome: Pass if the counts are equal; fail if they differ.

Example Usage: Staging Layer

A data team wants to ensure their stg_products model always has the same number of columns as the raw raw_products source, detecting any columns inadvertently added or dropped during transformation.

models:
  - name: stg_products
    tests:
      - dbt_expectations.expect_table_column_count_to_equal_other_table:
          compare_model: source('raw', 'products'

models:
  - name: stg_products
    tests:
      - dbt_expectations.expect_table_column_count_to_equal_other_table:
          compare_model: source('raw', 'products'

models:
  - name: stg_products
    tests:
      - dbt_expectations.expect_table_column_count_to_equal_other_table:
          compare_model: source('raw', 'products'

Any schema divergence between staging and source is caught before it propagates to downstream models.

Interested to Learn More?
Try Out the Free 14-Days Trial

More Articles

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.