Skip to content

unify name tuple changestead of refusing the result set - #43

Open
rusher wants to merge 1 commit into
1.1from
1.1-nametu
Open

rusher wants to merge 1 commit into
1.1from
1.1-nametu

Conversation

@rusher

@rusher rusher commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Use the alias when given (SELECT id AS user_id → user_id), otherwise the column name (SELECT id → id).

Have a unify rule (C and pure python have different constraints). That results in 4 conditions:

  • it is a valid Python identifier (str.isidentifier(), Unicode-aware:héllo,日本 are ok, but COUNT(*) will be renamed
  • it is not a hard keyword (def,class,None, …)
  • it does not start with an underscore (foo,,__class__fail)
  • no earlier column in the same result set already took it

…stead of refusing the result set

A member name is kept when collections.namedtuple accepts it: a valid identifier, not a keyword, no leading underscore, not already used. Any other name: a duplicate, "COUNT(*)", "def", "_foo", one that is not valid UTF-8 - becomes column_<index>, with _1, _2, ... appended should that name itself be taken. (One rule for the C and the pure-Python implementation)
cursor.description keeps the names as the server sent them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant