[sqlalchemy] mapping to a dictionary-based collection using a select

2013-06-17 Thread Chris Withers
Hi All, I have a model roughly like this: class Instrument(Base): __tablename__ = 'instrument' id = Column(String(10), primary_key=True) name = Column(String(100)) class Symbol(Base): __tablename__ = 'symbol' instrument_id = Column(String(10),

[sqlalchemy] between .one() and .first()

2013-06-17 Thread Chris Withers
Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more than one object, I have the query wrong and so want an exception. Is there

Re: [sqlalchemy] flask-sqlalchemy pysybase connections

2013-06-17 Thread Ladislav Lenart
Hello. This will probably be completely off-topic, but we have recently solved a similar issue. In our case it was cherrypy's fault, because it uses 'implicit' 'sesssions.locking' by default. It acquires web session's lock at the beginning of a web request processing and releases it at the end of

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Wichert Akkerman
On Jun 17, 2013, at 08:58 , Chris Withers ch...@simplistix.co.uk wrote: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more

Re: [sqlalchemy] [ANN] Modified WindowedRangeQuery recipe

2013-06-17 Thread Ladislav Lenart
Hello. This is the current version of our windowed query: from sqlalchemy.sql.expression import distinct def windowed_query(query, column, options_or_callback, window_size=100): Perform (a correct) yield_per() operation. See WindowedQuery.yield_per() for more. EXAMPLE: q

[sqlalchemy] SQLAlchemy 0.8.1 + fdb, row size

2013-06-17 Thread graf
I use sqlautocode to get declarative tables of the Firebird and now, when I try to insert new row with unicode value for the field to the database I got an error ValueError: Value of parameter (30) is too long, expected 20, found 22' which is Column('Myfield', VARCHAR(length=20)), The db

[sqlalchemy] sqlite in memory

2013-06-17 Thread Richard Gerd Kuesters
hi! curiosity [that may help me, lol]: is there a way to create a sqlite database in memory, then save it to disk after initial inserts are done? let's say I have around 2 gb of data to insert and ... it takes like forever. i still have not convinced my boss to buy a ssd, so ... :D cheers,

Re: [sqlalchemy] SA0.7.9 - poor query performance (full scan instead of index scan because of joined table inheritance)

2013-06-17 Thread Ladislav Lenart
Hello. Here is the fully self-contained regression of the issue, including the workaround for SA 0.7.9. Thank you again, because I wouldn't figure it out without your help (the select_from part). I haven't tried it on SA 0.9. If you have any questions, please ask. HTH, Ladislav Lenart On

[sqlalchemy] sqlite unique constraints?

2013-06-17 Thread Rj Ewing
I am trying to do a migration and am running into a problem where my unique constraints are being delete with sqlite, but works fine with postgres. It seems that unique constraints are not present in the table, even before the migration. Ex. engine = create_engine(sqlite:///my.db) Session =

Re: [sqlalchemy] sqlite in memory

2013-06-17 Thread Petr Viktorin
You can tell SQLite to disable syncing and journalling, it should get very fast then: if session.connection().dialect.name == 'sqlite': session.connection().execute(PRAGMA synchronous=OFF) session.connection().execute(PRAGMA journal_mode=OFF) Of course, your data will be

Re: [sqlalchemy] SA0.7.9 - poor query performance (full scan instead of index scan because of joined table inheritance)

2013-06-17 Thread Ladislav Lenart
Hello. I ended up with the following query: @classmethod def _find_contacts_fetch_window(cls, contact_cls, win): Special data-fetching query for contacts and all their related info including tags, partner, client,... NOTE: We build the FROM part entirely by hand,

[sqlalchemy] Sqlite migration unique constraint no available?

2013-06-17 Thread Rj Ewing
I am having problem with a migration removing a unique constraint when running a migration with sqlite. The migration works fine with postgres. For some reason, when doing something like: engine = create_engine(sqlite:///my.db) Session = sessionmaker(bind=engine) s = Session() metadata =

[sqlalchemy] Unique constraints disappearing

2013-06-17 Thread Rj Ewing
I am trying to do a migration and am running into a problem where my unique constraints are being delete with sqlite, but works fine with postgres. It seems that unique constraints are not present in the table, even before the migration. Ex. engine = create_engine(sqlite:///my.db) Session =

Re: [sqlalchemy] SA0.7.9 - poor query performance (full scan instead of index scan because of joined table inheritance)

2013-06-17 Thread Ladislav Lenart
Hello. I ended up with the following query: @classmethod def _find_contacts_fetch_window(cls, contact_cls, win): Special data-fetching query for contacts and all their related info including tags, partner, client,... NOTE: We build the FROM part entirely by hand,

Re: [sqlalchemy] mapping to a dictionary-based collection using a select

2013-06-17 Thread Michael Bayer
On Jun 17, 2013, at 2:36 AM, Chris Withers ch...@simplistix.co.uk wrote: Hi All, I have a model roughly like this: class Instrument(Base): __tablename__ = 'instrument' id = Column(String(10), primary_key=True) name = Column(String(100)) class Symbol(Base): __tablename__

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Michael Bayer
On Jun 17, 2013, at 5:33 AM, Wichert Akkerman wich...@wiggy.net wrote: On Jun 17, 2013, at 08:58 , Chris Withers ch...@simplistix.co.uk wrote: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned

Re: [sqlalchemy] SQLAlchemy 0.8.1 + fdb, row size

2013-06-17 Thread Michael Bayer
On Jun 17, 2013, at 9:44 AM, graf a.zhabotins...@gmail.com wrote: I use sqlautocode to get declarative tables of the Firebird and now, when I try to insert new row with unicode value for the field to the database I got an error ValueError: Value of parameter (30) is too long, expected

Re: [sqlalchemy] sqlite in memory

2013-06-17 Thread Richard Gerd Kuesters
Hmmm, never knew of that. All my constraints are already predefined and inserts are in order so I won't get a broken FK. I'll try that too see if it increases the speed (decreasing my headaches per build, lol). Thanks a lot, Petr! On 06/17/2013 11:18 AM, Petr Viktorin wrote: You can tell

Re: [sqlalchemy] Unique constraints disappearing

2013-06-17 Thread Michael Bayer
On Jun 15, 2013, at 4:32 PM, Rj Ewing ewing...@gmail.com wrote: I am trying to do a migration and am running into a problem where my unique constraints are being delete with sqlite, but works fine with postgres. It seems that unique constraints are not present in the table, even before

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Charlie Clark
Am 17.06.2013, 08:58 Uhr, schrieb Chris Withers ch...@simplistix.co.uk: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more than

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Petr Viktorin
Simply handling NoResultFound should work just fine... def zero_or_one(query): try: return query.one() except NoResultFound: return None On Mon, Jun 17, 2013 at 6:36 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 17, 2013, at 5:33 AM, Wichert Akkerman

[sqlalchemy] The problem with the update

2013-06-17 Thread Witold Greń
Hi, I'm Witold and learn Sqlalchemy :) I have a little problem, here it is: This is my DB: class Addressess(Base): __tablename__ = 'addressess' id = Column('id', Integer, Sequence('address_id_seq'), primary_key=True, index=True, unique=True, nullable=False) street =

Re: [sqlalchemy] sqlite in memory

2013-06-17 Thread Richard Gerd Kuesters
Petr, just found something intesting that may work for anyone: http://blog.marcus-brinkmann.de/2010/08/27/how-to-use-sqlites-backup-in-python/ I was able do create a database totally in memory and them just dump it to a file. The process now takes about 5 minutes, against one hour+ that it