[sqlalchemy] Inexplicable NoResultFound error

2015-08-29 Thread thatsanicehatyouhave
Hi, I have a script that's basically been running unmodified for years. In it, it performs an SQLAlchemy query that does a simple join between two tables: platePointing = session.query(PlatePointing).join(Plate).filter(Plate.plate_id==plateid).one() Suddenly, I'm getting a NoResultFound error

Re: [sqlalchemy] Self-join and autoload

2014-03-28 Thread thatsanicehatyouhave
On Mar 28, 2014, at 6:40 AM, Simon King si...@simonking.org.uk wrote: The alternative is to define the children relationship after the class has been defined: class PhotoObj(Base): __tablename__ = 'photoobj' __table_args__ = {'autoload':True, 'schema':'sdssphoto'}

[sqlalchemy] Self-join and autoload

2014-03-27 Thread thatsanicehatyouhave
Hi, I'm trying to configure a table with autoload but can't quite get the syntax to set up a self-relationship. This is my abbreviated) schema: CREATE TABLE sdssphoto.photoobj ( pk bigint NOT NULL DEFAULT nextval('photoobj_pk_seq'::regclass), parent_photoobj_pk bigint CONSTRAINT

Re: [sqlalchemy] Foreign key reflection error?

2011-11-04 Thread thatsanicehatyouhave
Hello, Thanks Mike for the comments. Before I answer the questions you asked, I want to note I found a workaround without making any changes to the database-- I just reversed the tables in the definition. At first I was using: Survey.bossSpectrumHeaders = relationship(BOSSSpectrumHeader,

[sqlalchemy] Foreign key reflection error?

2011-11-03 Thread thatsanicehatyouhave
Hi, I'm getting the following error with SQLAlchemy 0.7.3: sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relationship Survey.bossSpectrumHeaders. Specify a 'primaryjoin' expression. If 'secondary' is present, 'secondaryjoin' is needed as

Re: [sqlalchemy] Exclusive SELECT?

2011-06-01 Thread thatsanicehatyouhave
Hi M, Thanks very much for your help. Adding .with_lockmode('update') to my session.query statement worked like a charm! Now I just need to figure out how to catch exceptions that occur in the work unit in the thread, but that's a topic for another list... Cheers, Demitri -- You received

[sqlalchemy] Exclusive SELECT?

2011-05-31 Thread thatsanicehatyouhave
Hi, I'm working on a script using SQLAlchemy against a PostgreSQL database and using Python's multiprocessing. The pattern is for each thread to: - start a transaction (session.begin()) - retrieve the next row in table X that has not yet been processed - set a being_processed flag in the row so

[sqlalchemy] In-memory sqlite database to blob?

2011-03-04 Thread thatsanicehatyouhave
Hi, I'd like to write a script that creates an in-memory SQLite database via SQLAlchemy, but when I've finished with it I'd like to upload it as a file to a server, preferably without ever creating a temporary file on the client side. Is this possible? Cheers, Demitri -- You received this

Re: [sqlalchemy] In-memory sqlite database to blob?

2011-03-04 Thread thatsanicehatyouhave
Thanks for the pointers. I'l probably just write it to a file initially to keep it simple! Cheers, Demitri -- 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

[sqlalchemy] searching for new objects not yet in database

2010-11-12 Thread thatsanicehatyouhave
Hi, I just want to check on something. Let's say I've got a script that's populating a database and will commit the transaction at the end. It looks for a particular object (let's call it A), and if NoResultFound it creates a new object and does a session.add(A). What if in a later iteration

Re: [sqlalchemy] searching for new objects not yet in database

2010-11-12 Thread thatsanicehatyouhave
Thanks for the quick reply! On Nov 12, 2010, at 7:41 PM, Michael Bayer wrote: mm, right there that's not the default behavior. If you did an add(A), the next query() you do will autoflush. A is now in the database within the scope of the current transaction, so query() will find it. Yes,

Re: [sqlalchemy] Using the declarative base across projects

2010-07-20 Thread thatsanicehatyouhave
Hi, Just wanted to say thanks to those who helped me with this. Simon's solution was exactly what I was looking for (though I have to admit I don't exactly understand *how* it works!). But that's no longer an SQLAlchemy question... Cheers, Demitri On Jul 8, 2010, at 5:49 AM, King Simon-NFHD78

[sqlalchemy] Lazy load on a column basis?

2010-07-20 Thread thatsanicehatyouhave
Hi, Is lazy loading supported on a column by column basis, or only through relationships? Cheers, Demitri -- 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

Re: [sqlalchemy] Re: Unknown Issue Causing Extremely Slow Query

2010-07-19 Thread thatsanicehatyouhave
On Jul 19, 2010, at 4:08 PM, Michael Bayer wrote: so its going to be doing that somewhat inefficient isinstance(list) thing you see below, this appears to be how it handles arrays of arbitrary numbers of dimensions. This could be optimized if the ARRAY type accepted some clues as to how

Re: [sqlalchemy] Re: Unknown Issue Causing Extremely Slow Query

2010-07-19 Thread thatsanicehatyouhave
Hi Michael, Assuming I understood you correctly, I tried the code below. The result was the same (the query took 486 seconds). Since I autoload everything, I first adjust the column types to the class you defined. Did I misunderstand something? Thanks again for your help. Cheers, Demitri ---

Re: [sqlalchemy] Re: Unknown Issue Causing Extremely Slow Query

2010-07-19 Thread thatsanicehatyouhave
Hi, Pasted below is a profile of the earlier code posted. I did update it with your new definition of ARRAY Michael, but that only shaved off 18 seconds (down to 468s total) when run without the profiler. The large number of __new__ calls roughly tracks with the number of numeric values

[sqlalchemy] Using the declarative base across projects

2010-07-07 Thread thatsanicehatyouhave
Hi, I have a question that I can't find a satisfactory answer to. Apologies in advance if it's more of a Python question, but it's possible that there is a SA solution. I have a project that defines a database connection and classes based on database tables. A script that uses these classes

Re: [sqlalchemy] Using the declarative base across projects

2010-07-07 Thread thatsanicehatyouhave
Hi Lance, Thanks for your comments. On Jul 7, 2010, at 12:28 PM, Lance Edgar wrote: Why not just do this in project2 ? import project.DatabaseConnection as db Base = declarative_base(bind=db.engine) # ... etc. The DatabaseConnection class contains the particulars of the connection

[sqlalchemy] Sessions, threads, TurboGears best practice?

2009-10-19 Thread thatsanicehatyouhave
Hi, I'm hoping someone can help me with properly configuring a session/ transactions for multiple uses as I haven't been able to get it quite right. I've created a python module to contain my model classes and a connection class. This module wil be imported by both single-use scripts

[sqlalchemy] Re: Defining custom types

2009-10-15 Thread thatsanicehatyouhave
Hi Michael, Thanks for clarifying that for me. For anyone interested, this is what I ended up with: from sqlalchemy import String sa_major_version = sqlalchemy.__version__[0:3] if sa_major_version == 0.5: from sqlalchemy.databases import postgres

[sqlalchemy] Defining custom types

2009-10-12 Thread thatsanicehatyouhave
Hello, I have a custom type defined in my postgresql database, and this is giving me the warning: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/sqlalchemy/engine/base.py:1265: SAWarning: Did not recognize type 'fibertype' of column 'fiber_type'

[sqlalchemy] Re: Remove need for session in method?

2009-09-28 Thread thatsanicehatyouhave
Hi Tomasz, Thanks for your help - that solved the problem. On 26 Sep 2009, at 10:20, Tomasz Jezierski - Tefnet wrote: [...code snipped...] First... why don't you define this method with class definition? I don't use reflection but I think that it is possible... It's a

[sqlalchemy] Custom attribute in table class

2009-08-27 Thread thatsanicehatyouhave
Hi, I'm trying to create a custom/derived attribute on a table class. This is what I have defined: class Plate(Base): __tablename__ = 'plate' __table_args__ = {'autoload' : True} class Design(Base): __tablename__ = 'design' __table_args__ = {'autoload' : True}

[sqlalchemy] Re: Deleting multiple objects

2009-08-20 Thread thatsanicehatyouhave
On 19 Aug 2009, at 18:32, Mike Conley wrote: The delete method of query supports bulk deletes. In your case it might be something like session.query(Users).filter(User.officeid==office.id).delete() Any query can be used; there are probably more elegant ways to take advantage of the

[sqlalchemy] Deleting multiple objects

2009-08-19 Thread thatsanicehatyouhave
Hello, I have several objects from a relation that I'd like to delete. To me, this would be a natural syntax: session.delete(office.users) to delete all of the user objects. I get this error when doing this: raise exc.UnmappedInstanceError(instance)

[sqlalchemy] join + filter

2009-08-03 Thread thatsanicehatyouhave
Hi, I'm circling around an answer for a problem but am not quite getting it. I have two tables: Plugging and Cartridge. Plugging has a to-one relation to Cartridge, and the inverse relation is to-many. Cartridge has a field called number and plugging has a field called active. I want to

[sqlalchemy] Query with fields from different tables

2009-06-22 Thread thatsanicehatyouhave
Hi, I am doing a search across two tables for matching records, and I'm not quite sure how to work with the results of the query. For example: matches = session.query(TableA).from_statement(SELECT tableA.id, tableB.id FROM tableA, tableB WHERE etc) To me this doesn't really fit the model.

[sqlalchemy] Re: Testing the state of an object in a session.

2009-05-04 Thread thatsanicehatyouhave
Hi Michael, On 1 May 2009, at 20:50, Michael Bayer wrote: obj in session.new obj in session.dirty obj in session Cheers for that. I was actually on the right page in the documentation when I was looking for that.

[sqlalchemy] Testing the state of an object in a session.

2009-05-01 Thread thatsanicehatyouhave
Hi, Given a session object, is there a way to test if an object in the session is pending (or for that matter, transient, persistent, or detached)? Thanks! Demitri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

[sqlalchemy] Re: Auto-generating class definitions

2009-04-22 Thread thatsanicehatyouhave
Hi Huy, Thanks for your comments! On 22 Apr 2009, at 05:33, huy wrote: I guess it depends if you are going the standard SA table/mapping way or the sqlalchemy.ext.declarative way So this is a good question to ask. As I'm just starting out with SA, I have no legacy code to update, and thus

[sqlalchemy] Auto-generating class definitions

2009-04-21 Thread thatsanicehatyouhave
Hello, I'm trying to set up database access using SQLAlchemy, and wanted to get some advice from the experts on how to proceed. I'm using PostgreSQL as my database (shouldn't be important, I know) and will specify foreign keys in the database. I do not want to create or modify database

[sqlalchemy] Mapping and reflection question

2009-04-15 Thread thatsanicehatyouhave
Hello, I have a question about SQLAlchemy (well, I have a lot of questions, but I'll try to space them out a bit!). I'm very new to it (and python) but not databases and ORMs. I like that I can use reflection to define tables, and I really want to use that since I don't want to update