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
from psycopg.sql import SQL
QUERY = SQL("SELECT call.id AS id FROM call AS call WHERE id = %s")from psycopg.sql import SQL
QUERY = SQL("SELECT call.id FROM call WHERE id = %s")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()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
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()