Skip to content

raw sql is used as a subquery, when select a single column, ResultProxy.keys does not return the corresponding column name #6665

Closed
@WangWenQiang

Description

@WangWenQiang

Describe the bug

To Reproduce

from sqlalchemy import create_engine
from sqlalchemy import select
from sqlalchemy import text

# non-working MCVE edited by mike

engine = create_engine('sqlite://', echo=False)

one_col_sql = 'select 1 as col1'
multi_col_sql = 'select 1 as col1, 2 as col2'

def go(sql):
    table = text(sql).columns().alias()
    q = select(['*']).select_from(table)
    proxy = engine.execute(q)
    print(proxy.keys())

go(multi_col_sql)
go(one_col_sql)

Error
-Werror flag: python -Werror myprogram.py

if query single column, eg: query(one_col_sql) == ['*'],
but if query column more than 1, eg: query(multi_col_sql) == ['apartment_id', 'apartment_name']

Versions.

  • OS:
  • Python: 3.8.*
  • SQLAlchemy: 1.3.* & 1.4.*
  • Database: postgresql
  • DBAPI:postgresql

Additional context

Have a nice day!

Activity

sqla-tester

sqla-tester commented on Jun 23, 2021

@sqla-tester
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

consider "*" col as textual ordered https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2887

added
bugSomething isn't working
engineengines, connections, transactions, isolation levels, execution options
and removed
requires triageNew issue that requires categorization
on Jun 23, 2021
added this to the 1.4.x milestone on Jun 23, 2021
zzzeek

zzzeek commented on Jun 23, 2021

@zzzeek
Member

thanks for reporting

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

    bugSomething isn't workingengineengines, connections, transactions, isolation levels, execution options

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@WangWenQiang@sqla-tester

        Issue actions

          raw sql is used as a subquery, when select a single column, ResultProxy.keys does not return the corresponding column name · Issue #6665 · sqlalchemy/sqlalchemy