Thanks! Works great. On Jan 14, 2:27 am, "Michael Bayer" <mike...@zzzcomputing.com> wrote: > avdd wrote: > > I want to map a table with a postgresql array as a primary key. > > PostgreSQL supports it, and everything works until the session wants > > to use the list returned from the query as an instance key. How can > > I intercept the row returned to wrap it in a tuple? I can't figure > > out translate_row! > > id skip translate_row and instead use TypeDecorator around PGArray. > you'd override process_result_value to return tuple(value). > > > > > """ > > from sqlalchemy.orm import sessionmaker > > from sqlalchemy import Column, Integer, create_engine > > from sqlalchemy.ext.declarative import declarative_base > > from sqlalchemy.dialects.postgresql.base import ARRAY > > > engine = create_engine('postgresql:///avdd') > > DB = sessionmaker(bind=engine) > > > class A(declarative_base()): > > __tablename__ = 'a' > > ids = Column(ARRAY(Integer()), primary_key=True) > > > A.__table__.delete(bind=engine).execute() > > > a = A() > > a.ids = (1,2,3) > > > db = DB() > > db.add(a) > > db.commit() > > > del a, db > > > db = DB() > > print db.query(A).all() > > """ > > > Traceback (most recent call last): > > File "testarraypk.py", line 25, in <module> > > print db.query(A).all() > > File "lib/sqlalchemy/orm/query.py", line 1217, in all > > return list(self) > > File "lib/sqlalchemy/orm/query.py", line 1376, in instances > > rows = [process[0](row, None) for row in fetch] > > File "lib/sqlalchemy/orm/mapper.py", line 1681, in _instance > > instance = session_identity_map.get(identitykey) > > File "lib/sqlalchemy/orm/identity.py", line 145, in get > > state = dict.get(self, key, default) > > TypeError: unhashable type: 'list' > > -- > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To post to this group, send email to sqlalch...@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 sqlalch...@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.