Overview
Theselect-star rule flags the use of SELECT * in outermost queries. While convenient during development, SELECT * creates fragile code that can break when table schemas change.
Rule name: select-star
Default severity: Warning
When This Rule Triggers
This rule triggers when:SELECT *appears in the outermost querySELECT *appears in either side of aUNION,INTERSECT, orEXCEPToperation at the top level
- Explicit column names are listed in the outermost query
SELECT *appears only inside a CTE (Common Table Expression)SELECT *appears only in subqueries
Why It Matters
Schema Fragility
When you useSELECT *, your query implicitly depends on:
- The current order of columns in the table
- The current set of columns in the table
- The data types of all columns
- Receive columns in an unexpected order
- Receive unexpected columns it doesn’t handle
- Miss columns it expects
- Experience type mismatches
Performance Impact
Fetching all columns when you only need a few wastes:- Network bandwidth
- Memory in your application
- Database I/O and cache efficiency
Maintenance Clarity
Explicit column lists make it clear what data the query actually needs, improving code readability and maintainability.Examples
Problematic: SELECT * in outermost query
Problematic: SELECT * in outermost query
SELECT *, making it fragile to schema changes.Problematic: SELECT * in UNION
Problematic: SELECT * in UNION
SELECT * in the outermost query.Problematic: SELECT * with CTE at outer level
Problematic: SELECT * with CTE at outer level
SELECT *.Good: Explicit column list
Good: Explicit column list
Good: SELECT * only inside CTE
Good: SELECT * only inside CTE
SELECT * is used internally.Implementation Details
The rule works by:- Identifying
SELECTstatements at the outermost level - For set operations (
UNION,INTERSECT,EXCEPT), checking both left and right queries - Inspecting the target list for
ColumnRefnodes with anA_Starfield - Reporting a warning at the location of each
*found
select_star.go