Skip to content

Table column names for SQL queries with JOINS #23

Description

@cyrillay

Hello,

In the ColumnDescription returned inside the cursor.description, it feels like there is some useful metadata missing.
Could we have the table from which the column is from ?

For instance, when doing :

cursor.execute("SELECT a.description AS foo, b.description AS bar FROM a LEFT JOIN b ON a.id=b.id")

cursor.description contains the column names, but not their alias. In this case, it would return ['description', 'description'], when one could expect ['foo', 'bar'] so it is impossible to differentiate ambiguous columns, to assign them to the right elements in the result.

I think this method in __init__.py is the one which needs enhancement :

def _set_description(self, column_metadata):
      # see https://www.postgresql.org/docs/9.5/datatype.html
      self.description = []
      for column in column_metadata:
          col_desc = ColumnDescription(name=column["name"], type_code=self._pg_type_map.get(column["typeName"].lower(), str))
          self.description.append(col_desc)

The column_metadata should contain a tableName field, according to the boto3 docs, see the response syntax in here. Could it be added to the ColumnDescription object ?

Would it be possible to implement this feature ? Is there another way I am missing ?

Thanks in advance !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions