Re: [sqlalchemy] How to convert character set of the column with sqlalchemy?

2017-12-20 Thread Ken Liu
very good! It's fine. thank you, Mike Bayer ! On Wednesday, December 20, 2017 at 10:08:49 PM UTC+8, Mike Bayer wrote: > > On Wed, Dec 20, 2017 at 4:36 AM, Ken Liu > > wrote: > > I want to convert query.order_by(cast(Channel.cname, String) to > cast(cname > > AS CHAR CHARACTER SET gbk),how do I

[sqlalchemy] Re: KeyError when looping thru class objects to try and copy them

2017-12-20 Thread Tom Tanner
I moved `db.session.commit()` outside the loop. That seemed to fix the error. I'll post an update if I get more errors. On Wednesday, December 20, 2017 at 6:43:05 PM UTC-5, Lele Gaifax wrote: > > Tom Tanner > writes: > > > I want to query rows and copy them while changing an attribute of each.

Re: [sqlalchemy] KeyError when looping thru class objects to try and copy them

2017-12-20 Thread Mike Bayer
On Wed, Dec 20, 2017 at 5:38 PM, Tom Tanner wrote: > I want to query rows and copy them while changing an attribute of each. > Here's my code. > > colObjs= db.session.query(Column).filter_by(chart_id=oldChartID).all() > for colObj in colObjs: >make_transient(colObj) >print colObj.id >

[sqlalchemy] Re: KeyError when looping thru class objects to try and copy them

2017-12-20 Thread Lele Gaifax
Tom Tanner writes: > I want to query rows and copy them while changing an attribute of each. > Here's my code. > > colObjs= db.session.query(Column).filter_by(chart_id=oldChartID).all() > for colObj in colObjs: >make_transient(colObj) >print colObj.id >del colObj.id >colObj.cha

[sqlalchemy] KeyError when looping thru class objects to try and copy them

2017-12-20 Thread Tom Tanner
I want to query rows and copy them while changing an attribute of each. Here's my code. colObjs= db.session.query(Column).filter_by(chart_id=oldChartID).all() for colObj in colObjs: make_transient(colObj) print colObj.id del colObj.id colObj.chart_id= newChartID db.session.add(co

[sqlalchemy] Re: How do I copy an object and save to database?

2017-12-20 Thread Tom Tanner
Thank you On Wednesday, December 20, 2017 at 8:37:57 AM UTC-5, Lele Gaifax wrote: > > Tom Tanner > writes: > > > Lele, could you write the code showing how that would look? Thanks. > > Extending Mike's answer: > > from sqlalchemy.orm import make_transient > make_transient(someObj) #

Re: [sqlalchemy] How to convert character set of the column with sqlalchemy?

2017-12-20 Thread Mike Bayer
On Wed, Dec 20, 2017 at 4:36 AM, Ken Liu wrote: > I want to convert query.order_by(cast(Channel.cname, String) to cast(cname > AS CHAR CHARACTER SET gbk),how do I do that? please help me. this looks like MySQL so the character set option is present in the MySQL CHAR type: from sqlalchemy.dialect

[sqlalchemy] Re: How do I copy an object and save to database?

2017-12-20 Thread Lele Gaifax
Tom Tanner writes: > Lele, could you write the code showing how that would look? Thanks. Extending Mike's answer: from sqlalchemy.orm import make_transient make_transient(someObj) # someObj is no longer in the session del someObj.id# assume this is the primary key

[sqlalchemy] How to convert character set of the column with sqlalchemy?

2017-12-20 Thread Ken Liu
I want to convert query.order_by(cast(Channel.cname, String) to cast(cname AS CHAR CHARACTER SET gbk),how do I do that? please help me. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Comp

[sqlalchemy] Re: How do I copy an object and save to database?

2017-12-20 Thread Tom Tanner
Lele, could you write the code showing how that would look? Thanks. On Wednesday, December 20, 2017 at 2:22:49 AM UTC-5, Lele Gaifax wrote: > > Tom Tanner > writes: > > > Thanks, I used the first method. Follow up question: How do I get the > new > > primary key after running `session.commit()`