Re: [sqlalchemy] [psql] string escaping quirk in like clauses

2013-06-28 Thread Mike Conley
will disable escaping; don't know if the Python modules support that feature. http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html?highlight=.like#sqlalchemy.sql.operators.ColumnOperators.like -- Mike Conley On Fri, Jun 28, 2013 at 6:19 AM, Simon King si...@simonking.org.uk wrote: On Fri

Re: [sqlalchemy] datetime and engine

2012-03-30 Thread Mike Conley
The Oracle database only has one date type, and it includes time. If you require date only it is up to you to extract the date. Alternatively, if you really care about date only for all usage of that column, store it with a time of 00:00:00. On Mar 30, 2012 8:08 AM, jo jose.soa...@sferacarta.com

Re: [sqlalchemy] Deletion

2011-10-18 Thread Mike Conley
here is that in this case we are creating an explicit SQL delete statement without adding Peripheral instances to the session and so there is no knowledge that a related Actuator exists. Someone else might be able to give a better explanation. -- Mike Conley On Tue, Oct 18, 2011 at 9:03 AM

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Mike Conley
On Wed, Sep 28, 2011 at 8:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: On Sep 28, 2011, at 9:47 AM, Chris Withers wrote: On 28/09/2011 14:09, Michael Bayer wrote: I'm doing engine.execute('drop table if exists %s' + table.name) in the meantime, which just feels icky... oh

Re: [sqlalchemy] obtaining * field when more than 1 table

2011-09-16 Thread Mike Conley
, MSPResponse) should work. You get result rows with 2 items: a scalar for original_name and a MSPResponse object. You can then process the result like this: for row in result: ### access Files.original_name as row.original_name ### access MSPResponse as row[1] -- Mike Conley -- You received

Re: [sqlalchemy] Re: Error while using CAST

2011-09-14 Thread Mike Conley
Don't know what database you are using, but this looks like you are trying to cast the string 'testing' to an integer and the database engine says you can't do that. -- Mike Conley On Wed, Sep 14, 2011 at 9:51 AM, pravin battula pravin.batt...@gmail.comwrote: Sorry for the spelling

[sqlalchemy] Unregister an event listener

2011-09-08 Thread Mike Conley
the listener -- Mike Conley -- 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

Re: [sqlalchemy] Calculating percentage using subquery

2011-08-29 Thread Mike Conley
)).\ group_by(FilmParticipation.PartType) -- Mike Conley On Mon, Aug 29, 2011 at 3:05 PM, nospam lhfied...@gmail.com wrote: I'm trying to construct a query in sqlalchemy similiar to this: SELECT FilmParticipation.PartType, COUNT(*) AS Amount, 100*COUNT(*) /(SELECT count(*) FROM

Re: [sqlalchemy] Handling optional relationship

2011-08-19 Thread Mike Conley
, ForeignKey(Parent.id)) parent = relation(Parent, backref=backref('children', cascade=save-update,merge)) sess.add(Parent(children=[Child(),Child()])) sess.commit() p = sess.query(Parent).first() sess.delete(p) sess.commit() -- Mike Conley On Fri, Aug 19, 2011 at 12:10 PM, Mark Erbaugh m

Re: [sqlalchemy] Re: SQL Delete in session does not work

2011-08-16 Thread Mike Conley
of synchronize_session parameter to determine what is needed in your application -- Mike Conley -- 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

Re: [sqlalchemy] Re: SQL Delete in session does not work

2011-08-16 Thread Mike Conley
transaction come from? -- Mike Conley -- 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

Re: [sqlalchemy] Default values

2011-08-06 Thread Mike Conley
them unless you reflected the table or you coded the server side default in your code by hand. -- Mike Conley -- 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

Re: [sqlalchemy] writing a (sub)query

2011-07-27 Thread Mike Conley
0.7 has support for window functions. I haven't tried it in a subquery. http://www.sqlalchemy.org/docs/core/tutorial.html?highlight=window#window-functions -- Mike Conley On Wed, Jul 27, 2011 at 9:16 AM, Eduardo ruche...@googlemail.com wrote: I have the following statement : SELECT name

Re: [sqlalchemy] Question on the precedence of insert and delete in session flush

2011-07-27 Thread Mike Conley
to give up to the UOW code. After all if sequence is important this could very well be application dependent and the UOW might have to get really sophisticated to guess right. That increases the risk of taking a performance hit in the 90+% of cases where it doesn't matter. -- Mike Conley -- You

[sqlalchemy] engine.echo not working as expected

2011-07-27 Thread Mike Conley
before the connect() to get it to echo. -- Mike Conley -- 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

Re: [sqlalchemy] engine.echo not working as expected

2011-07-27 Thread Mike Conley
I saw that, but unless setting echo actually changes the Python logger configuration I don't see how it applies here. -- Mike Conley On Wed, Jul 27, 2011 at 12:31 PM, King Simon-NFHD78 simon.k...@motorolasolutions.com wrote: -Original Message- From: sqlalchemy@googlegroups.com

Re: [sqlalchemy] Re: default value from column

2011-07-13 Thread Mike Conley
in http://www.sqlalchemy.org/docs/core/schema.html -- Mike Conley -- 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

[sqlalchemy] Problem with DeclarativeMeta

2011-06-28 Thread Mike Conley
() -- Mike Conley -- 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

Re: [sqlalchemy] intersect_all vs chaining of filter

2011-06-22 Thread Mike Conley
WHERE book.title = ? AND book.title = ? AND book.title = ? AND book.title = ? -- Mike Conley -- 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

Re: [sqlalchemy] updates using declarative extention

2011-06-15 Thread Mike Conley
see http://www.sqlalchemy.org/docs/orm/query.html#sqlalchemy.orm.query.Query.update We use session.query(..).update(..,synchronize_session=False) for updates where we are sure about the criteria and session state. This generates an update statement without any selects. -- Mike Conley

Re: [sqlalchemy] sqlalchemy filter by count problem

2011-06-07 Thread Mike Conley
http://www.sqlalchemy.org/docs/06/orm/query.html#sqlalchemy.orm.query.Query.join for example: if the items relationship isn't declared .join((Item,User.id==Item.user_id)) generates the same SQL -- Mike Conley -- You received this message because you are subscribed to the Google Groups

Re: [sqlalchemy] update table row immediately after writing

2011-05-30 Thread Mike Conley
2011/5/30 Cornelius Kölbel cornelius.koel...@lsexperts.de OK, after some more reading and thinking, I think i managed it this way: self.session.add(at) self.session.flush() # At this point at contains the primary key id at.signature = self._sign( at )

Re: [sqlalchemy] insert record into dependency table

2011-05-11 Thread Mike Conley
,primary_key=True) confirmed = Column(Boolean,default=False, nullable=False) values = relationship(ModelAttributeValue) attr = ModelAttribute(confirmed=True) attr.values.append(ModelAttributeValue(value=1)) session.add(attr) session.commit() -- Mike Conley -- You received this message because

Re: [sqlalchemy] Re: Side by side versions on one machine.

2011-04-26 Thread Mike Conley
, then virtualenv might be the way to go. -- Mike Conley -- 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

Re: [sqlalchemy] Select NULL

2011-04-09 Thread Mike Conley
Use people.married_status == None to check for NULL -- Mike Conley -- 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

Re: [sqlalchemy] Execute a function on orphan

2011-04-09 Thread Mike Conley
and the group. -- Mike Conley -- 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

Re: [sqlalchemy] Automatically retrieving the row index

2011-04-07 Thread Mike Conley
Take a look at using ordering_list for the collection class on your relation. You add a position in season and SQLAlchemy will maintain the value. http://www.sqlalchemy.org/docs/orm/extensions/orderinglist.html -- Mike Conley -- You received this message because you are subscribed

Re: [sqlalchemy] MultipleResultsFound

2011-03-30 Thread Mike Conley
-- Mike Conley -- 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

Re: [sqlalchemy] Defining a relationship without a foreign key constraint?

2011-03-15 Thread Mike Conley
): __tablename__ = 'groups' group_id = Column(Integer, primary_key=True) group_nm = Column(String(10)) users = relation('User', backref='grp', primaryjoin='User.group_id==Group.group_id', foreign_keys='User.group_id') -- Mike Conley -- You received this message because you

Re: [sqlalchemy] Multi-get?

2011-01-26 Thread Mike Conley
the IN operator in SQL.) Thanks in advance. Did you try something like session.query(MyClass).filter(MyClass.id.in_([...list of ids...])).all() -- Mike Conley -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy

Re: [sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Mike Conley
with the rest of the relationship configuration. -- Mike Conley -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr

Re: [sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Mike Conley
, deals.c.deal_status=='active')) This is one advantage of using declarative because the primaryjoin can be defined as a string that will not be compiled until later. That can be deferred until after everything is defined. -- Mike Conley On Thu, Nov 11, 2010 at 1:33 PM, Jonathan Gardner jgard

Re: [sqlalchemy] Create_all() - Create_JustThese(engine, [Table1,Table2,....])?

2010-10-27 Thread Mike Conley
Check the docs, create_all has an optional tables= parameter. On Oct 27, 2010 8:18 AM, Martijn Moeling mart...@xs4us.nu wrote: Hi, I have a huge definition module where I create Python objects and use declarative. Since not all databases (Multiple for different customers) need all tables I do

Re: [sqlalchemy] Change echo at will

2010-08-26 Thread Mike Conley
On Thu, Aug 26, 2010 at 4:21 PM, Michael Hipp mich...@hipp.com wrote: Is there a way to set 'echo' at any time? Everything I can find sets it when the engine is created and doesn't seem to change it afterward. Thanks, Michael You can assign the engine.echo property to True or False any

Re: [sqlalchemy] how to do housekeeping jobs before using sqlalchemy and coworking with python sqlite3 and sqlalchemy ?

2010-08-26 Thread Mike Conley
On Wed, Aug 25, 2010 at 1:30 PM, keekychen.shared keekychen.sha...@gmail.com wrote: How to test if an existing database file is a valid sqlite3 format file before using sqlalchemy? Here is function we use import os, os.path as osp try: from pysqlite2 import dbapi2 as sqlite except:

Re: [sqlalchemy] create_all() fails silently

2010-08-05 Thread Mike Conley
On Thu, Aug 5, 2010 at 6:29 AM, Michael Hipp mich...@hipp.com wrote: On 8/4/2010 10:03 PM, Mike Conley wrote: Thanks. But by the time I'm done there will be at least a dozen of those otherfiles. Which one do I get Base from? You can put the declaration of Base in a common file

Re: [sqlalchemy] create_all() fails silently

2010-08-04 Thread Mike Conley
On Wed, Aug 4, 2010 at 9:39 PM, Michael Hipp mich...@hipp.com wrote: Can someone tell me why this code won't create any tables? The tables are defined in another file that calls declarative_base(). I presume the problem is that it doesn't know which tables to create. If so, how do I tell it

Re: [sqlalchemy] distinct query

2010-03-18 Thread Mike Conley
ON Shot.id = Asset.shot_id WHERE Shot.id = :id_1 -- Mike Conley -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr

Re: [sqlalchemy] ArgumentError: Only '='/'!=' operators can be used with NULL

2009-12-22 Thread Mike Conley
On Tue, Dec 22, 2009 at 2:34 AM, jo jose.soa...@sferacarta.com wrote: Hi all, I'm trying to solve this error... File /home/sfera/release/sicer/BASE/controller/controlli/sopralluogo.py, line 645, in verifiche Piano.c.data_inizio =data.get('data_sop') , File

Re: [sqlalchemy] Getting relation type from mapper

2009-12-10 Thread Mike Conley
. There might be a simpler approach, but it looks like this one should work. -- Mike Conley -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email

Re: [sqlalchemy] Functions on results of subquery question

2009-11-28 Thread Mike Conley
to this because using the .c. with ORM didn't feel natural. -- Mike Conley -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy

Re: [sqlalchemy] Weird error with update

2009-11-23 Thread Mike Conley
Why not use update({ESMagicNumber.last_access: datetime.datetime.now()}) ? one advantage of this syntax is that Python will raise an exception that last_access does not exist. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this

Re: [sqlalchemy] Getting a join in one object

2009-11-22 Thread Mike Conley
query() will return a tuple of the items listed in the query. In your query you are asking for a and b objects, so that is what you get. If you want the result to be individual columns directly, you need to list them individually. db.query(a.a, a.acol1, b.b, b.bcol1).\

Re: [sqlalchemy] more than one one to many relation

2009-11-22 Thread Mike Conley
this should work OK if you fix the ForeignKey definitions Column('parent_id', Integer, ForeignKey('parent.parent_id')) or Column('parent_id', Integer,ForeignKey(parent_table.c.parent_id)) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

Re: [sqlalchemy] Weird error with update

2009-11-20 Thread Mike Conley
On Fri, Nov 20, 2009 at 5:14 PM, Mariano Mara mariano.m...@gmail.comwrote: ... or, at least, is weird for me :) Hi everyone. I'm running a pylons controller with the following instruction: meta.Session.query(ESMagicNumber).filter(

[sqlalchemy] Re: column label and order by

2009-11-17 Thread Mike Conley
And you do need to quote the column name in order_by also. session.query(func.sum(X.amount).label('tot_amount')).group_by(X.date).order_by('tot_amount').limit(10) generates code SELECT sum(x.amount) AS tot_amount FROM x GROUP BY x.date ORDER BY tot_amount LIMIT 10 OFFSET 0

[sqlalchemy] Re: Query on a related object's field

2009-11-13 Thread Mike Conley
I haven't seen how to do this using the relation directly. I do: session.query(Someclass).join(OtherClass).filter_by(OtherClass.field==somevalue) I did do some experimenting with a more abstract approach, but did not find any need in my application. The only advantage is that it takes away the

[sqlalchemy] ConcurrentModificationError exception

2009-11-11 Thread Mike Conley
just in the unit testing stage. -- Mike Conley --~--~-~--~~~---~--~~ 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

[sqlalchemy] Infinite loop in SA

2009-11-11 Thread Mike Conley
') a=A() b=B() x={22:33} # does not loop if dictionary is empty a.b.append(b, x) # -- goes into infinite loop, should be a.b.append(b) which works OK -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] Re: ConcurrentModificationError exception

2009-11-11 Thread Mike Conley
Thanks, that helps. It looks like the problem is around a M:N relationship. There is some complex logic about whether or not the row on the :N side of the relation should be copied or the original referenced. The related maintenance of the supporting association table causes the update problem.

[sqlalchemy] Re: Infinite loop in SA

2009-11-11 Thread Mike Conley
That is pretty much what I expected. Considering it only occurs if the developer writes incorrect code, I wouldn't want to make the performance tradeoff. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy

[sqlalchemy] Re: Subquery questions

2009-11-10 Thread Mike Conley
On Tue, Nov 10, 2009 at 9:55 PM, jcm jonmast...@gmail.com wrote: Folks, I could do with some decent docs on subqueries. I've tried to play with what's on the website, but it's not helping me to convert the following into an SQLAlchemy subquery: select * from symbollistentries WHERE

[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread Mike Conley
The id is generate by the database engine, not SQLAlchemy, so session.add() does nothing to push your object to the database and generate the id. You need to execute session.flush() after session.add() to write the book to the database and generate the id. After the flush() operation, the book id

[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread Mike Conley
Using your class definitions, it seems to work. What is different? Base.metadata.bind=create_engine('sqlite:///') Base.metadata.create_all() session=sessionmaker()() bk_ids = {} for title in ('Tom Sawyer', 'Huck Finn'): book = Book(title=title) session.add(book) session.flush()

[sqlalchemy] Re: M:N self-reference

2009-11-08 Thread Mike Conley
Something like this? The association table is declared in the relationships, but never referenced when creating or accessing objects. class Assoc(Base): __tablename__ = 'assoc' parent = Column(Integer, ForeignKey('m_to_n.id'), primary_key=True) child = Column(Integer,

[sqlalchemy] Re: M:N self-reference

2009-11-05 Thread Mike Conley
of parent pointers in a child record; that leads to the requirement for an association table. No other way to do it. SQLAlchemy cannot change the data modeling needed here, but constructs available in SA can make the coding easier for managing the association table. Mike Conley

[sqlalchemy] Re: Renaming or copying tables

2009-11-03 Thread Mike Conley
there's nothing built in that does that.you might build your own using the way that tometadata() works to provide clues. So, something like this? (Ignoring schema for now) def copyinmetadata(table, to_name): Make copy of table in own metadata metadata = table.metadata

[sqlalchemy] Renaming or copying tables

2009-11-03 Thread Mike Conley
Is it possible to rename and/or copy a table object in metadata? That is I have a table t1 = Table('t1', metadata, ...) I want a copy of that table as t2 in the same metadata, or rename it to t2. For right now, this is metadata manipulation only ignoring the underlying database. -- Mike

[sqlalchemy] Re: How can i use insert/update with transactions

2009-10-29 Thread Mike Conley
Looks like you are trying to mix ORM and SQL expression constructs. Also, Insert() objects should be constructed via the insert() function. Try this conn = session.connection() # get handle to the session's connection t = conn.begin() res = conn.execute(insert(t_table).values(id=None,pv=6))

[sqlalchemy] Re: Multi table select?

2009-10-27 Thread Mike Conley
On Mon, Oct 26, 2009 at 10:09 PM, Bobby Impollonia bob...@gmail.com wrote: You can also create a view mapped to that union and use that as a virtual table so that you don't have to repeat the union specification for every query: http://www.w3schools.com/Sql/sql_view.asp I don't know if

[sqlalchemy] Re: How to label text columns in a query

2009-10-27 Thread Mike Conley
Only a couple of months late, but here is the final working recipe: class A(Base): __tablename__ = 'tbl_a' id = Column(Integer, primary_key=True) data = Column(String) class B(Base): __tablename__ = 'tbl_b' id = Column(Integer, primary_key=True) data = Column(String)

[sqlalchemy] Re: Shallow copying

2009-10-26 Thread Mike Conley
I see, but I need a proper shallow copy instead, with every attribute.. Is there no way? :/ What is missed? I am not sure what you mean by shallow copy. The fact that there are relations to be lazy loaded is present in the new object when instantiated. Obviously the objects pointed to by the

[sqlalchemy] Re: Shallow copying

2009-10-26 Thread Mike Conley
On Mon, Oct 26, 2009 at 9:13 AM, Joril jor...@gmail.com wrote: On 26 Ott, 13:41, Mike Conley mconl...@gmail.com wrote: I see, but I need a proper shallow copy instead, with every attribute.. Is there no way? :/ What is missed? I am not sure what you mean by shallow copy. The fact

[sqlalchemy] Re: ordering_list vs compound primary keys

2009-10-26 Thread Mike Conley
Blurb at 0xeb9f50 with identity key (class '__main__.Blurb', (99, 1)) conflicts with persistent instance Blurb at 0xecd2d0 -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post

[sqlalchemy] Re: Saved Queries (or text representation of the SQL)

2009-10-23 Thread Mike Conley
On Fri, Oct 23, 2009 at 12:45 PM, jeff jeff.sie...@seagate.com wrote: I would like to save a number of these in a database so size is important (the serialized select() was somewhat large...) so I would like to get the string representation of the raw SQL directly useable by sqlalchemy if

[sqlalchemy] Re: Saved Queries (or text representation of the SQL)

2009-10-23 Thread Mike Conley
On Fri, Oct 23, 2009 at 1:47 PM, Michael Bayer mike...@zzzcomputing.comwrote: Much easier to use serializer. I agree with that. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this

[sqlalchemy] Re: Shallow copying

2009-10-23 Thread Mike Conley
On Fri, Oct 23, 2009 at 12:40 PM, Joril jor...@gmail.com wrote: Hi everyone! I'm trying to automatically build a shallow copy of a SA-mapped object.. At the moment my function is just: newobj = src.__class__() for prop in class_mapper(src.__class__).iterate_properties: setattr(newobj,

[sqlalchemy] Re: bad result when querying for null values (in pk at least)

2009-10-15 Thread Mike Conley
add allow_null_pks to your mapper arguments See http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] Re: bad result when querying for null values (in pk at least)

2009-10-15 Thread Mike Conley
On Thu, Oct 15, 2009 at 9:21 AM, alexbodn.gro...@gmail.com wrote: thanks a lot mike, it's working great now. but this flag should be implied if one of the primary key fields is nullable (especially since it's not nullable by default). what would you think? You can argue just as easily

[sqlalchemy] Re: Simple join

2009-10-07 Thread Mike Conley
Now I want to build a query to get all Workstations which are related to server 'foo'. This works: ws = DBSession.query(WorkStation).select_from(join(WorkStation, DHCPServer)).filter(DHCPServer.label == 'foo').all() but It's too complex. Is there an easier way? Something like:

[sqlalchemy] Re: order by a field of related object

2009-10-06 Thread Mike Conley
Assuming you have the foreign keys defined, it should be fairly easy. session.query(Project).join(Country).order_by(Country.name) if you don't have the keys defined, you will need to add the join condition to the .join() -- Mike Conley

[sqlalchemy] Re: Number of row updated or deleted

2009-09-29 Thread Mike Conley
Use rowcount property of the ResultProxy returned from delete/update result = conn.execute(tbl.delete()) count = result.rowcount Note that the quality of the number will depend on the underlying database and Python dbapi. --~--~-~--~~~---~--~~ You received this

[sqlalchemy] Re: session.query object instead rowtuple

2009-09-28 Thread Mike Conley
The column is available as e.Namefile, no need to subscript with numbers. On Mon, Sep 28, 2009 at 6:07 AM, Christian Démolis christiandemo...@gmail.com wrote: Hi everybody, I have a little problem with session.query. I try to optimize my queries with only attributes that i need. When we

[sqlalchemy] Re: Circular Dependancy Hell

2009-09-26 Thread Mike Conley
You need to use argumentpost_update=True on your thumbnails relation http://www.sqlalchemy.org/docs/05/mappers.html#rows-that-point-to-themselves-mutually-dependent-rows http://www.sqlalchemy.org/docs/05/mappers.html#rows-that-point-to-themselves-mutually-dependent-rowsHere is a

[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread Mike Conley
Did you verify that the full query gives results? SELECT table_name FROM all_tables WHERE nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX') AND owner = 'SCHEM'; I've been away from Oracle for a while, but I do remember it is unusual, but still possible for user's tables to be in

[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread Mike Conley
What does the second query report for tablespace_name? SYSTEM? If so, you need to talk to your DBA about why the default tablespace for your owner is SYSTEM. Normally the system is configured to have user tables go somewhere else. From the SQLAlchemy side, the maintainers of

[sqlalchemy] Mapping arbitrary selectables

2009-09-15 Thread Mike Conley
, primary_key=[s2.c.bar]) # same error using [t2.c.bar] ArgumentError: Mapper Mapper|Two|%(31476816 anon)s could not assemble any primary key columns for mapped table '%(31476816 anon)s' -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you

[sqlalchemy] Re: Mapping arbitrary selectables

2009-09-15 Thread Mike Conley
Submitted ticket #1542 --~--~-~--~~~---~--~~ 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] Re: getting data from primary keys

2009-09-14 Thread Mike Conley
If I understand this, you want to construct a query that returns the primary keys in an arbitrary table? Try this: key_cols = [c for c in table.primary_key.columns] session.query(*key_cols).all() --~--~-~--~~~---~--~~ You received this message because you are

[sqlalchemy] Correlated subqueries and ORM

2009-09-12 Thread Mike Conley
somehow? -- Mike Conley --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: Update session extension after creation

2009-09-10 Thread Mike Conley
= [MySessionExtension()] to replace the existing extension or session.extensions.append(MySessionExtension()) to add yours to the list But understand the risk that this is modifying internals and might not work, and no guarantee it will work in future versions. -- Mike Conley On Thu, Sep 10, 2009

[sqlalchemy] Re: Update session extension after creation

2009-09-10 Thread Mike Conley
As expected, the simple test works. Something else is happening. In [7]: cpaste Pasting code; enter '--' alone on the line to stop. :Base=declarative_base() :Base.metadata.bind = create_engine('sqlite:///', echo=True) :class Foo(Base): :__tablename__ = 'foo' :id = Column(Integer,

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
Nothing hackish about it. The SQL is doing exactly what you want; union the posting tables and join the result to users. Simple enough that the database engine should construct a reasonable plan. -- Mike Conley On Wed, Sep 9, 2009 at 8:41 PM, Seth seedifferen...@gmail.com wrote: Ok Mike

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
posted earlier about labeling literals in the first query of a union. I'll reply to that thread again when I have the answer completed. -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
here is the sample code I am using http://pastebin.com/m6cd9c5dd -- Mike Conley On Wed, Sep 9, 2009 at 11:10 PM, Mike Conley mconl...@gmail.com wrote: On Wed, Sep 9, 2009 at 10:46 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Sep 9, 2009, at 8:41 PM, Seth wrote: Ok Mike

[sqlalchemy] Re: Cascade option, what does all mean?

2009-09-08 Thread Mike Conley
Your assumption should be correct. http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy.orm.relation On Tue, Sep 8, 2009 at 6:40 AM, Eloff dan.el...@gmail.com wrote: Hi, I see cascade='all, delete, delete-orphan' in the tutorial, but I thought I read in the docs

[sqlalchemy] Re: distinct (or group by) with max in sqlalchemy - how to?

2009-09-06 Thread Mike Conley
See the documentation at http://www.sqlalchemy.org/docs/05/sqlexpression.html#functions Something like this Using ORM mapped classes session.query(Tabl.name, func.max(Tabl.cnt)).group_by(Tabl.name).all() or SQL expression language

[sqlalchemy] Re: Single row of a One to Many query

2009-09-03 Thread Mike Conley
client -- Mike Conley --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: http://www.sqlalchemy.org/docs/05/ormtutorial.html

2009-09-03 Thread Mike Conley
the compilation error. -- Mike Conley --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: extended inserts

2009-08-31 Thread Mike Conley
bulk insert capability is the INSERT ... SELECT FROM syntax. DB API's, such as the Python DBAPI executemany() or SQLAlchemy, accept something like a bulk insert, but actually generate multiple insert statements. -- Mike Conley --~--~-~--~~~---~--~~ You received

[sqlalchemy] Re: How to label text columns in a query

2009-08-28 Thread Mike Conley
AS somestuff, 'A' AS source FROM a UNION SELECT b.data AS somestuff, 'B' AS source FROM b) AS anon_1 The correct code would be SELECT anon_1.somestuff AS somestuff, anon_1.source AS source etc. -- Mike Conley --~--~-~--~~~---~--~~ You received

[sqlalchemy] Joining subqueries

2009-08-28 Thread Mike Conley
using Session.query.join(), the first parameter to query() must be a mapped entity or an attribute of a mapped entity. Is that true? -- Mike Conley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-28 Thread Mike Conley
It works and will probably be OK. Using this style (query for user multiple times) in a really big database could lead to a performance problem depending on how the underlying database engine constructs a query plan. Try it and see how it goes. -- Mike Conley On Fri, Aug 28, 2009 at 2:22 PM

[sqlalchemy] Re: how to make unique constrain within ORM

2009-08-28 Thread Mike Conley
Constraints are defined in __table_args__ try: __table_args__ = ( UniqueConstraint('api_id', 'daskey_id', name='uix_1'), {'mysql_engine':'InnoDB'}) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-27 Thread Mike Conley
AttributeError: 'NoneType' object has no attribute 'base_mapper' Probably because the subq is first in the list and is not an entity -- Mike Conley On Thu, Aug 27, 2009 at 5:05 PM, Mike Conley mconl...@gmail.com wrote: Assuming a declarative based class USER exists, then you can join each

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-27 Thread Mike Conley
statement SQL would look something like this: SELECT qry.a, qry.b, qry.c, user.x FROM (SELECT a,b,c FROM p1 UNION ALL SELECT a,b,c FROM p2 UNION ALL SELECT a,b,c FROM p3) as qry JOIN USER on qry.a = USER.a but I can't seem to get this result in SQLAlchemy -- Mike Conley

[sqlalchemy] How to label text columns in a query

2009-08-27 Thread Mike Conley
AS somestuff, anon_1.somelabel as somelabel FROM (SELECT a.data AS somestuff, 'A' as somelabel FROM a UNION ALL SELECT b.data AS data, 'B' FROM b) AS anon_1 which will give the desired result -- Mike Conley --~--~-~--~~~---~--~~ You received this message because

[sqlalchemy] Re: multiple insert with default values

2009-08-26 Thread Mike Conley
is: when inserting many records, provide same value list for each row. -- Mike Conley On Wed, Aug 26, 2009 at 5:36 AM, menuge men...@gmail.com wrote: Hi all, I d like to insert a list of dictionary in a simple MySQL table but, I have a problem, in my case, the MySQL default values

[sqlalchemy] Re: Declarative way of delete-orphan

2009-08-26 Thread Mike Conley
Add cascade='delete-orphan' to the relation definition for children. cascade='all,delete-orphan' is also a fairly common option. See the documentation for other options in cascade. http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy.orm.relation -- Mike Conley On Wed

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-26 Thread Mike Conley
Did you try something like this? q1=session.query(P1.userid, P1.extra, P1.title, P1.body) q2=session.query(P2.userid, 'X', P2.title, P2.body) q3=session.query(P3.userid, 'X', P3.title, P3.body) q=q1.union_all(q2).union_all(q3) -- Mike Conley On Wed, Aug 26, 2009 at 10:45 PM, Seth

  1   2   >