On Dec 9, 2010, at 11:14 AM, Christian Démolis wrote: > "Could not locate column in row for column '%s'" % key) > sqlalchemy.exc.NoSuchColumnError: 'Could not locate column in row for column > \'" > lng"\'' > > I don t want to call a column by litteral name.
you're thinking of the "label()" function. literal() and literal_column() produce standalone expressions, and are documented at: http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=literal_column#sqlalchemy.sql.expression.literal http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=literal_column#sqlalchemy.sql.expression.literal_column Below is an example application illustrating their use in the context you describe. Hope this helps. from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) data = Column(String(50)) engine = create_engine('sqlite://', echo=True) Base.metadata.create_all(engine) sess = Session(engine) sess.add_all([Foo(data='f1'), Foo(data='f2'), Foo(data='f3')]) sess.commit() assert sess.query( Foo.id, Foo.data, literal_column('"technique_number_one"'), literal('technique_number_two')).\ order_by(Foo.id).all() == [ (1, 'f1', "technique_number_one", "technique_number_two"), (2, 'f2', "technique_number_one", "technique_number_two"), (3, 'f3', "technique_number_one", "technique_number_two"), ] > I want to attach an arbitrary string of my choice to each row results of my > query. > Look the screenshot to see what i want. > > Thx > > 2010/12/9 Michael Bayer <[email protected]> > you want to use literal_column('"coucou"') to achieve that effect, or if a > bind is OK then just use literal("coucou"). > > > On Dec 9, 2010, at 8:30 AM, Christian Démolis wrote: > >> Hi, >> >> SELECT IdActe, "coucou" >> FROM `acte` >> WHERE 1 >> >> How to attach a string to each result of a query ? >> >> i try that but it doesn't work :( >> s = model.session.query(milieu, model.Dossier.NomEntreprise, >> model.Dossier.AgendaSensGroupement, model.Dossier.AgendaUnite, "Coucou") >> >> Thx >> Chris >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > <Clipboard01.jpg> -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
