[sqlalchemy] Infer (and create) Schema from Example Object/Dictionary

2011-12-16 Thread Gregg Lind
My search skills are failing me, and I hope you all can help. (Apologies that there is some heresy here) Assumptions: 1) Suppose I have objects made from json (dicts of strings, lists of dicts, etc.) 2) (for simplicity, assume these nestings don't go very deep) 3) getting this right 90% of

[sqlalchemy] Postgresql Partition / INHERIT and table names....

2010-09-13 Thread Gregg Lind
Suppose this is my table: a_table = Table( 'a_table', metadata, Column('ts',Integer, index=True, nullable=False), Column('country',String, index=True, nullable=False), Column('somestat',Integer,nullable=False),

[sqlalchemy] Re: Postgresql Partition / INHERIT and table names....

2010-09-13 Thread Gregg Lind
, Gregg Lind wrote: Suppose this is my table:    a_table = Table(        'a_table', metadata,        Column('ts',Integer, index=True, nullable=False),        Column('country',String, index=True, nullable=False),        Column('somestat',Integer,nullable=False

[sqlalchemy] SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
suppose: summary_table = Table( 'summary', metadata, Column('ts',Integer, index=True, nullable=False), Column('url',String, index=True, nullable=False), Column('hits',Integer, nullable=False), PrimaryKeyConstraint('ts','url','hits',name='summary_pk'),

[sqlalchemy] Re: SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
/index.html' AND faketable.ts = 1829292929 AND faketable.hits 100 If I had this string repr with filled params, I could just a string sub / regex, and go all the way into hackery! On Aug 4, 10:20 am, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 4, 2010, at 10:34 AM, Gregg Lind wrote

[sqlalchemy] Re: SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
Thank you for the more detailed explanation! I will do some experiments with it! Gregg On Aug 4, 12:39 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 4, 2010, at 1:26 PM, Gregg Lind wrote: Thanks for the advice! One minor nit.  At least in my experience, str(bound query

[sqlalchemy] Postgresql OVER clauses

2010-07-06 Thread Gregg Lind
I'd like to use the postgresql OVER constructions, as seen at http://www.postgresql.org/docs/8.4/static/tutorial-window.html. Some of the things I tried: # gives an extra comma, which is fail. print select([s.ts,PARTITION OVER( ts )]) SELECT summary.ts, PARTITION OVER( ts ) FROM summary #

[sqlalchemy] PG copy_expert, and sessions

2010-06-19 Thread Gregg Lind
I've been trying to use pg's copy_expert semantics with sessions, but something is eluding me. Observations: 1. It seems like I have to wrap the copy_expert cursor in a transaction and commit() in order to make it actually fire (see pgsql_copy below). 2. When I try wrapping it in

[sqlalchemy] Re: Troubleshooting 'too many clients already'

2010-06-18 Thread Gregg Lind
can't see the config file directly) Thanks again for the help! Gregg On Jun 17, 8:04 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 17, 2010, at 8:14 PM, Gregg Lind wrote: What built-in tools / techniques should I use when trying to troubleshoot the 'too many clients already' fatal

[sqlalchemy] Troubleshooting 'too many clients already'

2010-06-17 Thread Gregg Lind
What built-in tools / techniques should I use when trying to troubleshoot the 'too many clients already' fatal error. 1. Connecting to PG locally, fwiw, 2. I have full privileges on the db My connections can come from at least: - create_engine I try to be careful to del engine after I'm done

[sqlalchemy] server_version_info

2010-02-24 Thread Gregg Lind
Is there a nice way to get server_version_info from an existing connection or engine? Right now it looks quite buried in (for pg): sqlalchemy.database.postgres.PGDialiect().server_version_info(myconnection). -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] Declarative issues, with compound foreign key

2009-09-15 Thread Gregg Lind
What I think I'm seeing is that an object can be created even without it's ForeignKeyConstraint being filled. To run the test code below: $ dropdb test18; createdb test18; python testcode.py This builds on http://groups.google.com/group/sqlalchemy/browse_thread/thread/eb240f3f2555a5e7/ . I

[sqlalchemy] Re: Declarative issues, with compound foreign key

2009-09-15 Thread Gregg Lind
Thank you both for the advice. Dern NULLs causing trouble again. GL On Tue, Sep 15, 2009 at 4:34 PM, Conor conor.edward.da...@gmail.com wrote: On Sep 15, 4:08 pm, Michael Bayer mike...@zzzcomputing.com wrote: Gregg Lind wrote: What I think I'm seeing is that an object can be created

[sqlalchemy] Re: making an instance read-only

2009-08-25 Thread Gregg Lind
Based on Michael Bayer's hint, I built this instance-level changeable object. It used Declarative, which actually makes it a bit tougher, but this code should work for pypo's also. It's hackish in that it just monkeys with __setattr__, but it's clear(ish) what's happening.

[sqlalchemy] Re: index in SA

2009-08-20 Thread Gregg Lind
If you need to use some SQL is that is not supported by UniqueConstraint, PrimaryKeyConstraint and friends, you can use the DDL statement: # DDL to only run on postgres, incorporating declarative style from sqlalchemy.schema import DDL DDL('''ALTER TABLE orgdata ADD

[sqlalchemy] Can child-side of a one-to-many create the parent side?

2009-08-14 Thread Gregg Lind
I have a many-to-one relation, let's say between Address and User, both created using Declarative. I would like it that if an Address references a User, it will create that User, if it doesn't exist. Otherwise, it should use the existing one. There should be no addresses in the table that don't

[sqlalchemy] Re: Can child-side of a one-to-many create the parent side?

2009-08-14 Thread Gregg Lind
Bayer mike...@zzzcomputing.comwrote: Gregg Lind wrote: I have a many-to-one relation, let's say between Address and User, both created using Declarative. I would like it that if an Address references a User, it will create that User, if it doesn't exist. Otherwise, it should use

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-24 Thread Gregg Lind
parts, other than the hop id. On Thu, Jul 23, 2009 at 8:13 PM, Michael Bayermike...@zzzcomputing.com wrote: On Jul 23, 2009, at 8:43 PM, Gregg Lind wrote: Hm.  I appreciate the help, but something is clearly still failing here. session.query(Route,*sq.c).join(sq.c.max_hop) ArgumentError

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-24 Thread Gregg Lind
, and for making SqlA such a great (and powerful!) product. Thanks! GL On Fri, Jul 24, 2009 at 11:59 AM, Michael Bayermike...@zzzcomputing.com wrote: Gregg Lind wrote: session.query(Route.ts,Route.startpoint,Route.target,func.max(Route.hop_id).label('max_hop'))\         .group_by(Route.ts

[sqlalchemy] Declarative, correlated subqueries

2009-07-23 Thread Gregg Lind
I have read over http://www.sqlalchemy.org/docs/05/ormtutorial.html#using-subqueries and http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg11439.html, but I'm having trouble putting the pieces together. In the demo() below, I want to find the row in the database with the max for every

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-23 Thread Gregg Lind
On Thu, Jul 23, 2009 at 3:24 PM, Michael Bayermike...@zzzcomputing.com wrote: im assuming you're using MySQL since the GROUP BY below doesn't accommodate every column in the subquery (would be rejected by most DBs). Corrected. It was Sqlite, but good catch. youll want to query each column

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-23 Thread Gregg Lind
, Michael Bayermike...@zzzcomputing.com wrote: On Jul 23, 2009, at 5:20 PM, Gregg Lind wrote: How do I implement this join?  If I do this: sq = session .query (Route .ts ,Route .startpoint,Route.target,func.max(Route.hop_id).label('max_hop')) sq = sq.group_by(Route.ts,Route.startpoint

[sqlalchemy] Queries in historical db's, where the join depends on having an overlapping timestamp (or other filter condition)

2009-07-16 Thread Gregg Lind
''' Based on the thread titled filter relation based on column value at http://groups.google.com/group/sqlalchemy/browse_thread/thread/0db7423d986ba543 and some others, I'm curious about how to better get my SqlA code working with historical (better term?) databases, where the relational state

[sqlalchemy] Re: Queries in historical db's, where the join depends on having an overlapping timestamp (or other filter condition)

2009-07-16 Thread Gregg Lind
of magic as you suggest! Thanks for the advice! Gregg On Thu, Jul 16, 2009 at 10:17 AM, Michael Bayermike...@zzzcomputing.com wrote: Gregg Lind wrote: Questions: 1.  Is there a SQLAlchemical way to write group_snapshot_ts into     a declarative class, such that the joins and loader respect

[sqlalchemy] Re: Queries in historical db's, where the join depends on having an overlapping timestamp (or other filter condition)

2009-07-16 Thread Gregg Lind
Jess, Thanks for posting the actual class :) Just reading the description use contains_eager didn't tell me enough about how to make it happen. Cheers, Gregg On Thu, Jul 16, 2009 at 12:54 PM, jessjesslp...@gmail.com wrote: I believe that I asked Michael a similar question, in a different

[sqlalchemy] Re: Declarative base -- only add a constraint if particular db engine

2009-05-29 Thread Gregg Lind
and make this answer easier to find? Gregg On Fri, May 29, 2009 at 12:10 PM, Michael Bayer mike...@zzzcomputing.com wrote: Gregg Lind wrote: I use declarative base for defining classes. I have a constraint that only works in Postgres.  How do I declare that constraint lowername_check only

[sqlalchemy] Re: Declarative base -- only add a constraint if particular db engine

2009-05-29 Thread Gregg Lind
)     return buf.getvalue() On Fri, May 29, 2009 at 12:27 PM, Gregg Lind gregg.l...@gmail.com wrote: As always, thank you for the complete, exhaustive answer.  This particular thing is definitely and edge case, and rather non-obvious, so thank you for walking me through it. Either of those

[sqlalchemy] Re: Questions on SQLA Queries

2009-05-27 Thread Gregg Lind
I believe by map function, Timothy may be implying that you should use any of the python idioms for converting iterables of tuples to a straight tuple. The one I like best from itertools import chain q = session.query(User.name) #(User is a class) names = itertools.chain(*q.all() ) But you

[sqlalchemy] Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just insert into the table directly (using SqlA expression language) than to insert the objects via session.flush(). In the attached tests, I'm observing a 10x -20x

[sqlalchemy] Re: Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
Some followups: Python 2.4.3 on 64-bit linux. Timings are near identical in SA 0.5.2 and 0.5.3. On Apr 8, 9:57 am, Gregg Lind gregg.l...@gmail.com wrote: Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just

[sqlalchemy] Re: Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
...@zzzcomputing.com wrote: Gregg Lind wrote: Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just insert into the table directly (using SqlA expression language) than to insert the objects via session.flush

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Gregg Lind
I believe you want session.expunge() or session.expunge_all(). GL On Wed, Apr 8, 2009 at 6:05 PM, Chris Lewis cfle...@gmail.com wrote: Hi everyone! I have a threaded application which deals with a lot of records (it generates hundreds of thousands in an hour). I have a Database module

[sqlalchemy] export and import JSON from database (JSON type)

2009-02-25 Thread Gregg Lind
How does one create a TypeDecorator to export and import JSON to a database using SA? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] Re: export and import JSON from database (JSON type)

2009-02-25 Thread Gregg Lind
Thank you, that's simpler than my attempts, for sure! On Wed, Feb 25, 2009 at 10:27 AM, Roger Demetrescu roger.demetre...@gmail.com wrote: On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database

[sqlalchemy] Re: Events Undo/Redo Functionality?

2009-02-24 Thread Gregg Lind
nightmarish. I don't have any insights on the SA front, alas. Gregg Lind On Tue, Feb 24, 2009 at 2:41 PM, paniq303 paniq...@googlemail.com wrote: On Feb 24, 5:16 pm, a...@svilendobrev.com wrote: these are two general patterns, observer/listener and undo/redo (command-pattern), which have nothing