Metacenta

Maintainability · rule sql-select-star-output

select * in SQL transformation files

A Metacenta review checks this under the rule SQL files select explicit columns. Everything below applies whether or not you ever commission one.

What this rule checks

For SQL projects without dbt, this rule flags files that write a table or view whose output reaches an upstream relation through *. A * over a CTE that lists its columns passes. A view that only mirrors one table, with no join, is left alone.

Why it matters

A column added upstream appears here without a code change, and a renamed one disappears without an error. Readers of the table see the change before anyone has reviewed it.

How to fix it

List columns instead of select * in the SQL. List the columns in the statement that writes the relation. A view that deliberately mirrors one table can keep *; say so in the file.

Before:

create or replace table analytics.orders as
select *
from raw.shop_orders
where status != 'test';

After:

create or replace table analytics.orders as
select order_id, customer_id, ordered_at, status
from raw.shop_orders
where status != 'test';

When it is fine to leave

A table that must carry every column of its source, such as a raw landing copy, is correct to use *. A mirroring view with more than one statement is not recognised as one, so tell us and the finding comes out of your report.

What we need to check it

The .sql files, read from your repository with read-only access or uploaded. We keep only relation names, counts and a fingerprint per file, so the finding is medium confidence.