Skip to content
Sarj Code Standards

no-redundant-sql-alias

Remove SQL aliases that repeat the original relation or column name.

Why

A self-alias adds syntax without naming a distinct role or result field. It obscures useful aliases among repeated names.

Fix

Remove an alias whose PostgreSQL identifier equals the original table or bare column name. Keep role aliases for self joins, renamed outputs, quoted case distinctions and alias column lists.

Examples

Before — flagged Aliases repeat the existing names
app/call_store.py
from psycopg.sql import SQL
QUERY = SQL("SELECT call.id AS id FROM call AS call WHERE id = %s")
After — preferred Use the existing relation and column names
app/call_store.py
from psycopg.sql import SQL
QUERY = SQL("SELECT call.id FROM call WHERE id = %s")
Before — flagged Remove a self-alias from a closed literal result column
app/literal_rows.py
from psycopg import Connection
def literal_rows():
with Connection.connect() as connection:
return connection.execute(
'SELECT "r"."id" AS "id" FROM (VALUES (1)) AS "r"("id")'
).fetchall()
After — preferred A closed literal column keeps its implicit output name
app/literal_rows.py
from psycopg import Connection
def literal_rows():
with Connection.connect() as connection:
return connection.execute(
'SELECT "r"."id" FROM (VALUES (1)) AS "r"("id")'
).fetchall()
Autofix output
app/literal_rows.py
from psycopg import Connection
def literal_rows():
with Connection.connect() as connection:
return connection.execute(
'SELECT "r"."id" FROM (VALUES (1)) AS "r"("id")'
).fetchall()