Re: [sqlalchemy] Could not locate column in row for column

2014-02-13 Thread Igal Kreimer
updated pymysql to version 0.6.1 and it worked for me. thx alot 2014-02-12 19:27 GMT+02:00 Michael Bayer mike...@zzzcomputing.com: And you updated pymysql? Or no? Sent from my iPhone On Feb 12, 2014, at 10:56 AM, Igal Kreimer igal.k...@gmail.com wrote: yes it does. exactly the same

[sqlalchemy] Re: Twisted + SQLAlchemy

2014-02-13 Thread Pavel Aborilov
now, I'm using it like this: @defer.inlineCallbacks def jsonrpc_get(self, id): self.log.debug(get device with id %s % id) device = yield deferToThread(self.devices.get, id) // then generate output from device, where device is ORM object if devices.get method I use

[sqlalchemy] How to tell the cardinality of RelationshipProperty?

2014-02-13 Thread Guido Winkelmann
Hi, Reading through the docs, I could not find out how to tell the cardinality of an object of type sqlalchemy.orm.properties.RelationshipProperty, i.e. whether it is one-to-many, many-to-one or many-to-many. Mostly, I just need to know whether a relationship refers to just one object or a

Re: [sqlalchemy] How to tell the cardinality of RelationshipProperty?

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 6:23 AM, Guido Winkelmann gu...@ambient-entertainment.de wrote: Hi, Reading through the docs, I could not find out how to tell the cardinality of an object of type sqlalchemy.orm.properties.RelationshipProperty, i.e. whether it is one-to-many, many-to-one or

Re: [sqlalchemy] How to tell the cardinality of RelationshipProperty?

2014-02-13 Thread Guido Winkelmann
Am Donnerstag, 13. Februar 2014 15:46:31 UTC+1 schrieb Michael Bayer: On Feb 13, 2014, at 6:23 AM, Guido Winkelmann gu...@ambient-entertainment.de javascript: wrote: Hi, Reading through the docs, I could not find out how to tell the cardinality of an object of type

[sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
I'm trying to do something like this: class Animal(Base): __tablename__ = 'animals' id_ = Column(Integer, primary_key=True) sire_id = Column(Integer, ForeignKey('animals.id_')) dam_id = Column(Integer, ForeignKey('animals.id_')) sire = relationship('Animal',

Re: [sqlalchemy] How to tell the cardinality of RelationshipProperty?

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 11:46 AM, Guido Winkelmann gu...@ambient-entertainment.de wrote: Am Donnerstag, 13. Februar 2014 15:46:31 UTC+1 schrieb Michael Bayer: On Feb 13, 2014, at 6:23 AM, Guido Winkelmann gu...@ambient-entertainment.de wrote: Hi, Reading through the docs, I

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I'm trying to do something like this: class Animal(Base): __tablename__ = 'animals' id_ = Column(Integer, primary_key=True) sire_id = Column(Integer, ForeignKey('animals.id_')) dam_id = Column(Integer,

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:06 AM, Josh Kuhn wrote: I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships Thanks. I'm just not sure how to specify it when there

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:04 AM, Michael Bayer wrote: On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I don't see a first_owner relationship defined above, so the above example is not complete. The approach using foreign_keys is the correct approach to resolving ambiguity in join

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Josh Kuhn
I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships On Thu, Feb 13, 2014 at 12:04 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 13,

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 12:16 PM, Michael Hipp mich...@redmule.com wrote: On 2/13/2014 11:04 AM, Michael Bayer wrote: On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I don't see a first_owner relationship defined above, so the above example is not complete. The approach

Re: [sqlalchemy] How to tell the cardinality of RelationshipProperty?

2014-02-13 Thread Guido Winkelmann
Am Donnerstag, 13. Februar 2014 18:01:27 UTC+1 schrieb Michael Bayer: On Feb 13, 2014, at 11:46 AM, Guido Winkelmann gu...@ambient-entertainment.de javascript: wrote: Am Donnerstag, 13. Februar 2014 15:46:31 UTC+1 schrieb Michael Bayer: On Feb 13, 2014, at 6:23 AM, Guido Winkelmann

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:45 AM, Michael Bayer wrote: primaryjoin=and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id) Thank you. That works great. And thanks for the explanation. Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

Re: [sqlalchemy] array types using OracleDialect

2014-02-13 Thread Amos Smith
I found the missing space before literal_processor in my earlier listing, poor font selection hid that pretty well - still not sure why I couldn't see that earlier apologies again for that post. The new listing below now runs to completion but literal_processor method is not called for my UDT

Re: [sqlalchemy] array types using OracleDialect

2014-02-13 Thread Michael Bayer
like this: class LiteralBindParam(BindParameter): pass @compiles(LiteralBindParam) def literal_bind(element, compiler, **kw): kw['literal_binds'] = True return compiler.visit_bindparam(element, **kw) class ArrayType(UserDefinedType): def get_col_spec(self): return ARRAY

Re: [sqlalchemy] array types using OracleDialect

2014-02-13 Thread Amos Smith
Thanks! ... this is working nicely. With a bit of customization this gives me an interim solution for passing lists to stored procs using Oracle dialect. I'm still hoping to find a way to bind array parameters outside of PL/SQL through cx_Oracle later. - Original Message - From:

Re: [sqlalchemy] array types using OracleDialect

2014-02-13 Thread Michael Bayer
you know if you just want to spit out a string and don’t mind calling a function it’s much easier than that: from sqlalchemy import literal_column def oracle_array(arr): return literal_column(int_array( + , .join(str(v) for v in arr) + )”) ret =

Re: [sqlalchemy] array types using OracleDialect

2014-02-13 Thread Amos Smith
Thanks - makes sense. I have a pre-existing need to treat these arrays as columns in some instances, so I think there's merit in the more complex solution using UDT. Anticipated eventual use of ArrayType is something like: class MyClass(Base): __tablename__ = 'test' # Columns

[sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Hello, I'm new to SQLAlchemy and have searched high and low for a solution to my problem so I'm hoping someone here can help. I have a query where I need to apply the 'order by' clause dynamically (both the column and the direction). So a 'static' version of my query would be: studies =

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 6:21 PM, Tony Garcia tnyr...@gmail.com wrote: Hello, I'm new to SQLAlchemy and have searched high and low for a solution to my problem so I'm hoping someone here can help. I have a query where I need to apply the 'order by' clause dynamically (both the column and the

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Hmm.. I see what you're saying, but the column can be from any of the tables queried from, not just the Study table. So it could be Study.study_id, System.system_name, Site.site_id, etc. Also won't that getattr() call just return a string? I was under the impression that you had to pass a column

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Oops -- disregard the [start:end] at the end of the query and replace that with .all() On Thu, Feb 13, 2014 at 7:50 PM, Tony Garcia tnyr...@gmail.com wrote: Hmm.. I see what you're saying, but the column can be from any of the tables queried from, not just the Study table. So it could be

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Actually, now I see that your suggestion would get me the column object (not a string), but it would still restrict me to the study table. On Thu, Feb 13, 2014 at 7:53 PM, Tony Garcia tnyr...@gmail.com wrote: Oops -- disregard the [start:end] at the end of the query and replace that with

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Michael Bayer
everything in python is ultimately in a namespace, the names are strings, the values are the objects. like if you had “myapp.model” as a module, and in that module were Study and Site, you could say: from myapp import model Study = getattr(model, “Study”) same thing. If you want to poke

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Gotcha. Thanks Michael. Once I get the code working I'll post it here. Off to bed now, though. Cheers, Tony On Thursday, February 13, 2014 8:49:14 PM UTC-5, Michael Bayer wrote: everything in python is ultimately in a namespace, the names are strings, the values are the objects. like

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Josh Kuhn
I don't know if this is what you're thinking, but you can also just build a query object in different ways if you want to query = session.query(Study).options( joinedload(Study.system), joinedload(Study.site)).