我试图使用SQLAlchemy核心从表中选择数据。
import sqlalchemy as sa
...
with database_engine.connect() as conn:
s = map(dict, conn.execute(sa.select([destination.c])))
print s但我得到了以下错误:
/wowcomputers/.virtualenvs/project/lib/python2.7/site-packages/sqlalchemy/sql/selectable.pyc in __init__(self, columns, whereclause, from_obj, distinct, having, correlate, prefixes, suffixes, **kwargs)
2450 self._raw_columns = []
2451 for c in columns:
-> 2452 c = _interpret_as_column_or_from(c)
2453 if isinstance(c, ScalarSelect):
2454 c = c.self_group(against=operators.comma_op)
/wowcomputers/.virtualenvs/project/lib/python2.7/site-packages/sqlalchemy/sql/elements.pyc in _interpret_as_column_or_from(element)
3852 # be forgiving as this is an extremely common
3853 # and known expression
-> 3854 if element == "*":
3855 guess_is_literal = True
3856 elif isinstance(element, (numbers.Number)):
<string> in <lambda>(self, other)
/wowcomputers/.virtualenvs/project/lib/python2.7/site-packages/sqlalchemy/sql/base.pyc in __eq__(self, elements, other)
569 for c in getattr(other, "_all_columns", other):
570 for local in self._all_columns:
--> 571 if c.shares_lineage(local):
572 l.append(c == local)
573 return elements.and_(*l)
AttributeError: 'unicode' object has no attribute 'shares_lineage'我做错了什么?
发布于 2016-03-18 14:48:36
使用sqlachemy.core执行select时,需要向select传递一个可选选项列表。
sa.select([destination.c.column1, destination.c.column2])当您只是将所有列传递到select语句时,忘记删除包装列表是一个常见的错误,所以请更改
sa.select([destination.c])到这个
sa.select(destination.c)https://stackoverflow.com/questions/36087402
复制相似问题