Re: [sqlalchemy] Re: Translating T-SQL UPDATE FROM to SQLAlchemy
On Nov 23, 2011, at 6:50 PM, Andrew Buza wrote: > > > On Nov 21, 11:47 am, Michael Bayer wrote: >> >> I can tell you that there are two trac tickets regarding this functionality, >> and this patch in particular has a @compiles recipe that does the basic idea: >> >> http://www.sqlalchemy.org/trac/attachment/ticket/1944/enhance2.py >> >> The various patches that need to be reconclied/tested are at: >> >> http://www.sqlalchemy.org/trac/ticket/1944http://www.sqlalchemy.org/trac/ticket/2166 >> >> A key thing holding back the entire feature being built in is that Oracle >> has similar functionality but implements it entirely differently. This is >> a common issue Oracle introduces by doing things in a totally nonstandard >> way (like CONNECT BY...). >> >> That said, the straight string or @compiles approach will allow this to >> function now in a rudimental way. @compiles is documented at: >> >> http://www.sqlalchemy.org/docs/core/compiler.html > > Thanks! Good to know this will likely be supported at some point. For > now I'll probably use a straight string, but I'll take a look at > @compiles and the patch mentioned in your other message. yeah the feature is now committed to the tip, so just get the latest .gz from the download page and it should be good to go. docs: http://www.sqlalchemy.org/docs/core/tutorial.html#multiple-table-updates -- 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.
[sqlalchemy] Re: Translating T-SQL UPDATE FROM to SQLAlchemy
On Nov 21, 11:47 am, Michael Bayer wrote: > > I can tell you that there are two trac tickets regarding this functionality, > and this patch in particular has a @compiles recipe that does the basic idea: > > http://www.sqlalchemy.org/trac/attachment/ticket/1944/enhance2.py > > The various patches that need to be reconclied/tested are at: > > http://www.sqlalchemy.org/trac/ticket/1944http://www.sqlalchemy.org/trac/ticket/2166 > > A key thing holding back the entire feature being built in is that Oracle has > similar functionality but implements it entirely differently. This is a > common issue Oracle introduces by doing things in a totally nonstandard way > (like CONNECT BY...). > > That said, the straight string or @compiles approach will allow this to > function now in a rudimental way. @compiles is documented at: > > http://www.sqlalchemy.org/docs/core/compiler.html Thanks! Good to know this will likely be supported at some point. For now I'll probably use a straight string, but I'll take a look at @compiles and the patch mentioned in your other message. -- 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.
Re: [sqlalchemy] sqlalchemy memory usage
Python processes in CPython don't release memory back to the OS. On Nov 23, 2011, at 10:14 AM, lestat wrote: > if I do > > for x in xrange(1): >u = User.query.get(x) > > that python process memory up to 70 mb, and after cycle I try do > > db.session.close_all() > > or > > db.session.expire_all() > > but process memory not clear and it still 70 mb. > > If I working with millions of objects and try clearing memory, it use > all operating memory in system. > > How I can solve this problem? > > Thanks. > > -- > 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.
Re: [sqlalchemy] Association Object creation
On Nov 23, 2011, at 5:20 AM, Enrico Morelli wrote: > On Wed, 23 Nov 2011 10:59:03 +0100 > Enrico Morelli wrote: > > >> These are the mappers: >> mapper(Ligand, ligand_table, >> properties={ >> 'ligand':relationship(LigandLigand, >> primaryjoin=and_(ligand_table.c.id==ligand_ligand_table.c.ligand_id1, >> ligand_table.c.id==ligand_ligand_table.c.ligand_id2), >> backref=backref('ligandligand') ), }) >> >> mapper(LigandLigand, ligand_ligand_table, >> properties={ >> 'first_sphere': relationship(Ligand, >> >> primaryjoin=and_(ligand_ligand_table.c.ligand_id2==ligand_table.c.id, >> >> ligand_ligand_table.c.ligand_id1==ligand_table.c.id), >> backref=backref('root')), >> }) >> >> When I try to access to the ligand.ligand properties, this is empty >> even if in the db there are relations. Where is the problem? >> >> Thanks >> >> > > I think to have solved the problem changing the logical operator in the > primaryjoin from and_ to or_. > > Now when I remove the relations I have the following warning: > SAWarning: Multiple rows returned with uselist=False for lazily-loaded > attribute > LigandLigand.ligandligand' value = callable_(passive=passive) it means a relationship is expecting many-to-one or one-to-one and getting more than one row back.Setting uselist=True on that backref would resolve this issue, though if you only intend for one row to come back there you might want to triple-check what SQL is being emitted. The configuration here is already outside the normal realm of a "relationship" between two tables (not a traditional foreign key to primary key) so you may have to change or forego the usage of relationship() here.If it were me I'd just use two relationships to represent "ligand1" and "ligand2". -- 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.
[sqlalchemy] sqlalchemy memory usage
if I do for x in xrange(1): u = User.query.get(x) that python process memory up to 70 mb, and after cycle I try do db.session.close_all() or db.session.expire_all() but process memory not clear and it still 70 mb. If I working with millions of objects and try clearing memory, it use all operating memory in system. How I can solve this problem? Thanks. -- 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.
Re: [sqlalchemy] add results in a python object
On 11/17/2011 01:42 PM, raulna wrote: Hi, i need save results in a python object from multiples querys, like: for user in users: phones = DBSession.query(Phone).filter('... python_object = python_object + phones ?> How can i append this results in unique object? The simplest is to fetch all results from a query and concatenate the lists: results = query_1.all() + query_2.all() + query_3.all() -- 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.
Re: [sqlalchemy] Association Object creation
On Wed, 23 Nov 2011 10:59:03 +0100 Enrico Morelli wrote: > These are the mappers: > mapper(Ligand, ligand_table, >properties={ > 'ligand':relationship(LigandLigand, > primaryjoin=and_(ligand_table.c.id==ligand_ligand_table.c.ligand_id1, >ligand_table.c.id==ligand_ligand_table.c.ligand_id2), > backref=backref('ligandligand') ), }) > > mapper(LigandLigand, ligand_ligand_table, >properties={ > 'first_sphere': relationship(Ligand, > > primaryjoin=and_(ligand_ligand_table.c.ligand_id2==ligand_table.c.id, > > ligand_ligand_table.c.ligand_id1==ligand_table.c.id), >backref=backref('root')), >}) > > When I try to access to the ligand.ligand properties, this is empty > even if in the db there are relations. Where is the problem? > > Thanks > > I think to have solved the problem changing the logical operator in the primaryjoin from and_ to or_. Now when I remove the relations I have the following warning: SAWarning: Multiple rows returned with uselist=False for lazily-loaded attribute 'LigandLigand.ligandligand' value = callable_(passive=passive) What means? -- --- (o_ (o_//\ Coltivate Linux che tanto Windows si pianta da solo. (/)_ V_/_ +--+ | ENRICO MORELLI | email: more...@cerm.unifi.it | | * * * *| phone: +39 055 4574269 | | University of Florence| fax : +39 055 4574253 | | CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY| +--+ -- 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.
[sqlalchemy] Association Object creation
Dear all, I have to create an association object that have to relate elements of the same table. These are the table definition: ligand_table = Table('ligand', metadata, Column('id', types.Integer, primary_key=True), Column('number', types.Integer, nullable=False), Column('name', types.Unicode(4), nullable=False), ) ligand_ligand_table = Table('ligand_ligand', metadata, Column('ligand_id1', types.Integer, ForeignKey('ligand.id'),primary_key=True), Column('ligand_id2', types.Integer, ForeignKey('ligand.id'),primary_key=True), Column('interaction_id',types.Integer, ForeignKey('interaction.id')), Column('interaction_type', types.Unicode(10), nullable=False), Column('distance', types.Float, nullable=False), ) These are the mappers: mapper(Ligand, ligand_table, properties={ 'ligand':relationship(LigandLigand, primaryjoin=and_(ligand_table.c.id==ligand_ligand_table.c.ligand_id1, ligand_table.c.id==ligand_ligand_table.c.ligand_id2), backref=backref('ligandligand') ), }) mapper(LigandLigand, ligand_ligand_table, properties={ 'first_sphere': relationship(Ligand, primaryjoin=and_(ligand_ligand_table.c.ligand_id2==ligand_table.c.id, ligand_ligand_table.c.ligand_id1==ligand_table.c.id), backref=backref('root')), }) When I try to access to the ligand.ligand properties, this is empty even if in the db there are relations. Where is the problem? Thanks -- --- (o_ (o_//\ Coltivate Linux che tanto Windows si pianta da solo. (/)_ V_/_ +--+ | ENRICO MORELLI | email: more...@cerm.unifi.it | | * * * *| phone: +39 055 4574269 | | University of Florence| fax : +39 055 4574253 | | CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY| +--+ -- 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.