Skip to content
Sarj Code Standards

no-select-star

Prefer explicit column projections over SELECT * in embedded SQL.

Why

Wildcard projections couple row shape and query cost to unrelated schema changes.

Fix

List every required column explicitly in the projection.

Examples

Before — flagged Inspect native-decoded query text
src/page.ts
db.query("SEL\u0045CT * FROM runs");
After — preferred Ignore native-decoded comment data
src/page.ts
db.query("SEL\x45CT id FROM runs /* SELECT * FROM runs */");
Before — flagged Do not select every column
src/runs.ts
db.prepare(`SELECT * FROM runs`).all();
After — preferred Select the required columns
src/runs.ts
db.prepare(`SELECT id, status FROM runs`).all();
Before — flagged Expand the authored columns of an owned literal relation
src/literal-rows.ts
import { Client } from "pg";
export async function literalRows() {
const authoredLiteralClient = new Client();
try {
await authoredLiteralClient.connect();
return (
await authoredLiteralClient.query(
'SELECT * FROM (VALUES (1, 2)) AS "authored"("a", "b")',
)
).rows;
} finally {
await authoredLiteralClient.end();
}
}
After — preferred Preserve the explicit authored literal columns
src/literal-rows.ts
import { Client } from "pg";
export async function literalRows() {
const authoredLiteralClient = new Client();
try {
await authoredLiteralClient.connect();
return (
await authoredLiteralClient.query(
'SELECT "authored"."a", "authored"."b" FROM (VALUES (1, 2)) AS "authored"("a", "b")',
)
).rows;
} finally {
await authoredLiteralClient.end();
}
}
Autofix output
src/literal-rows.ts
import { Client } from "pg";
export async function literalRows() {
const authoredLiteralClient = new Client();
try {
await authoredLiteralClient.connect();
return (
await authoredLiteralClient.query(
'SELECT "authored"."a", "authored"."b" FROM (VALUES (1, 2)) AS "authored"("a", "b")',
)
).rows;
} finally {
await authoredLiteralClient.end();
}
}
Before — flagged The outer projection still selects every column
src/queries.ts
db.query("SELECT EXISTS((SELECT * FROM jobs)), * FROM runs");
After — preferred Quoted arithmetic operands are not wildcards
src/queries.ts
db.query('SELECT "units" * "price" AS total FROM entries');