sure probably, just compile the expression through the dialect and its fine

On Jun 21, 2011, at 3:28 PM, Filip Zyzniewski - Tefnet wrote:

> Hi,
> 
> I got an idea today and thought that maybe SQLAlchemy could support that 
> (copy at http://ideone.com/t42G4 ):
> ======================================================
> # Fails with Python-2.7.0 and SQLAlchemy-0.7.1
> 
> import sqlalchemy
> import sqlalchemy.ext.declarative
> 
> Base = sqlalchemy.ext.declarative.declarative_base(mapper = 
> sqlalchemy.orm.mapper)
> 
> 
> engine = 
> sqlalchemy.create_engine('postgres://tefbusiness_test:None@/tefbusiness_test_2',
>  echo = False)
> 
> session = sqlalchemy.orm.scoped_session(
>     sqlalchemy.orm.sessionmaker(
>         bind = engine,
>         autocommit = False,
>     )
> )
> 
> Base.metadata.bind = engine
> 
> class Person(Base):
>     Id = sqlalchemy.Column( sqlalchemy.types.Integer, primary_key = True, 
> autoincrement = True)
>     __tablename__ = 'person'
>     firstName = sqlalchemy.Column( sqlalchemy.types.String(128), nullable = 
> False)
>     lastName = sqlalchemy.Column( sqlalchemy.types.String(128), nullable = 
> False)
>     name = sqlalchemy.orm.column_property(
>         sqlalchemy.func.lower(firstName + ' ' + lastName)
>     )
> 
>     __table_args__ = (sqlalchemy.schema.Index('foo', name.columns[0]), {})
> 
> """
> Traceback (most recent call last):
>   File "column_property_2.py", line 20, in <module>
>     class Person(Base):
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/ext/declarative.py",
>  line 1128, in __init__
>     _as_declarative(cls, classname, cls.__dict__)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/ext/declarative.py",
>  line 1027, in _as_declarative
>     **table_kw)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/schema.py",
>  line 265, in __new__
>     table._init(name, metadata, *args, **kw)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/schema.py",
>  line 340, in _init
>     self._init_items(*args)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/schema.py",
>  line 64, in _init_items
>     item._set_parent_with_dispatch(self)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/events.py",
>  line 227, in _set_parent_with_dispatch
>     self._set_parent(parent) 
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/schema.py",
>  line 2112, in _set_parent
>     ColumnCollectionMixin._set_parent(self, table)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/schema.py",
>  line 1808, in _set_parent
>     self.columns.add(col)
>   File 
> "/home/filip/gitsrc/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/sql/expression.py",
>  line 2115, in add
>     self[column.key] = column
> AttributeError: 'Function' object has no attribute 'key'
> """
> ======================================================
> 
> If Index() could accept clauses as columns, then maybe we could get something 
> like:
>     name = sqlalchemy.orm.column_property(
>         sqlalchemy.func.lower(firstName + ' ' + lastName),
>         index = True
>     )
> 
> Most of the needed pieces are already in place.
> PostgreSQL can do stuff like this:
> ======================================================
> test=# CREATE INDEX ix_foo ON "teryt_Street" (lower(prename || ' ' || 
> postname));
> CREATE INDEX
> test=# 
> ======================================================
> 
> What do you think :)?
> 
> regards,
> Filip Zyzniewski
> Tefnet
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to