Hi does anyone know if is possible to declaratively concatenate two
columns together which you can later do query's on.
E.g. if I wanted to compute a new column course_name made up of
CONCAT(course_code,course_name)
Base = declarative_base()
class Course(Base):
__tablename__ = 'Course'
course_code = Column(VARCHAR(length=4), nullable=False)
course_num = Column(INTEGER(), nullable=False)
course_name = func.CONCAT(course_code,course_num) # only an
example, this doesn't actually work
So later you could do queries on the Course table like
course_data =
session.query(Course).filter( Course.course_name.op('regexp')
('^A.*4') )).first()
print course_data.course_name
It is possible to do a query to generate the data outside the Course
class as below, but how can you
make it as a normal mapped column in the Course class ?
query = session.query( func.CONCAT(Course.course_code,
Course.course_num) )
query = query.filter( func.CONCAT(Course.course_code,
Course.course_num).op('regexp')('^A.*4') )
Cheers
Royce
--
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.