[sqlalchemy] Re: Postgres - Backup - Restore

2008-11-10 Thread Chris Miles
On Nov 10, 4:57 am, Petr Kobalíček [EMAIL PROTECTED] wrote: I have postgres related problem. I'm normally developing with sqlite, but we are using postgres on the server. The problem is that sqlalchemy probably remembers primary keys and after database restore it will start in all tables

[sqlalchemy] conn.execute('CREATE SCHEMA %(s)s', {'s':s}) escape schema name,but it shouldn't, and raise ProgrammingError

2008-11-10 Thread sector119
Hi! I use PostgreSQL and when I try to create schema I use following command conn.execute('CREATE SCHEMA %(s)s', {'s':s}) I get raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or

[sqlalchemy] Re: Removing aggregate function from query results

2008-11-10 Thread Simon
Hi, you could simply get the Bowler objects from the results by saying results = [r[0] for r in results] I'm not sure whether you query is correct, though. Usually, you cannot select columns which are not in the GROUP BY clause or which are not aggregated - after grouping, you have several

[sqlalchemy] Session and postgres_returning

2008-11-10 Thread paftek
Hi, I am using SQLAlchemy with PostgreSQL 8.3. Today I just discovered the great postgres_returning functionnality. Dumb question : Is it possible to take advantage of it in session mode ? In other words, is it possible for session.add() to issue only one INSERT INTO ... RETURNING ... query

[sqlalchemy] Re: Memory leak - is session.close() sufficient?

2008-11-10 Thread joelanman
Thanks Simon - just checked and I'm running 2.5.2 on my machines. From experimenting - I'm not so sure I have a memory leak, so much as just using a lot of memory. I didn't realise that when Python frees memory, it doesnt necessarily become free in Linux. I think that possibly all that's

[sqlalchemy] Removing aggregate function from query results

2008-11-10 Thread Ian Charnas
Hello Alchemy Land! If I have a simple test-case with Bowler objects and City objects, and I want to use func.max and group_by in order to find the highest scorers in each city... I might do something like this: max_score = func.max(Bowler.highscore).label('highest_score') results =

[sqlalchemy] Re: Memory leak - is session.close() sufficient?

2008-11-10 Thread Julien Cigar
Note that a lot of database drivers cache *everything* in memory when you .fetchall(), fetchone() or fetchmany(x). So all those operations consume the same amout of memory : result = cursor.execute(...) for i in result: ... data = result.fetchall() for i in data: ... data =

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 4:33 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: I'm no SQL expert, so please take this with a pinch of salt, but as far as I know, conditions in the 'WHERE' clause of an SQL statement are applied BEFORE any grouping, so you can't use grouping functions (such as

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of John Hunter Sent: 10 November 2008 14:07 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: select where field=max(field) On Mon, Nov 10, 2008 at 4:33 AM, King Simon-NFHD78

[sqlalchemy] Newbie: Adding a column after database table has been created, declarative

2008-11-10 Thread Jules Stevenson
Hi, Apologies for lowering the general IQ of the list, I'm very new to web apps and databases. I had a declarative table: class ArkContact(Base): table of all contacts __tablename__ = 'contacts' id = Column(Integer, primary_key=True) project_id = Column(Integer,

[sqlalchemy] how to use Sql functions in object-relational objects?

2008-11-10 Thread fanlix
hi: In my app there is a user_table, with a column access_time. Without sqlalchemy, just update user_table set access_time = Now() , With sqlalchemy and user as a object-relational object, I have to make a app time and do user.access_time = now() ? or a better way?

[sqlalchemy] Re: Removing aggregate function from query results

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 5:35 AM, Ian Charnas wrote: Hello Alchemy Land! If I have a simple test-case with Bowler objects and City objects, and I want to use func.max and group_by in order to find the highest scorers in each city... I might do something like this: max_score =

[sqlalchemy] default=0.0 on Float Column produces `col` float default NULL

2008-11-10 Thread Simon
Hi all, I'm using SA 0.5.0rc3 and MySQL 5.0.51a on Mac OS X 10.4.11. I have a table with a float column and would like to have a default value of 0: Column('col', Float(), default=0.0) However, executing metadata.create_all(engine) yields CREATE TABLE `Table` ( ... `col` float default

[sqlalchemy] Re: problem with join, count on 0.5.0rc3

2008-11-10 Thread Cito
The new behavior is exactly what I expect, namely that query.count() returns the same as len(query.all()). Are there cases in which this does not make sense or where this would not work? -- Christoph --~--~-~--~~~---~--~~ You received this message because you are

[sqlalchemy] Re: Memory leak - is session.close() sufficient?

2008-11-10 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of joelanman Sent: 10 November 2008 00:21 To: sqlalchemy Subject: [sqlalchemy] Re: Memory leak - is session.close() sufficient? Thanks for all the advice - I've changed my unicode settings

[sqlalchemy] Re: schema inspection api

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 2:25 AM, Randall Smith wrote: Just to make sure we're considering the same plan, I don't plan to make any API changes that would cause breakage. All changes are additions including the public API and some new dialect methods (get_views, get_indexes, ...). Most of

[sqlalchemy] Re: default=0.0 on Float Column produces `col` float default NULL

2008-11-10 Thread jason kirtland
Simon wrote: Hi all, I'm using SA 0.5.0rc3 and MySQL 5.0.51a on Mac OS X 10.4.11. I have a table with a float column and would like to have a default value of 0: Column('col', Float(), default=0.0) However, executing metadata.create_all(engine) yields CREATE TABLE `Table` ( ...

[sqlalchemy] Re: conn.execute('CREATE SCHEMA %(s)s', {'s':s}) escape schema name,but it shouldn't, and raise ProgrammingError

2008-11-10 Thread Michael Bayer
Postgres doesn't allow bind parameters to be used with CREATE SCHEMA - it expects an identifier, not a literal value.When I try it on my system I don't get the E behavior you're getting, I get : sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near 'foo' LINE 1:

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 12:08 PM, John Hunter wrote: On Mon, Nov 10, 2008 at 10:05 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: Actually, the section after that (Using Subqueries) probably does something very close to what you want. What's the result of these lines: q1 =

[sqlalchemy] Re: 0.5.0rc3 - kinterbasdb.ProgrammingError: (0, 'Invalid cursor state. The cursor must be open to perform this operation.')

2008-11-10 Thread Werner F. Bruhin
Michael, Michael Bayer wrote: I know what this is and it should be working in r5280. I don't have access to firebird here so we weren't able to run the tests on it before rc3 was out. Thanks for the quick reply. Looking at the changes doc these will be included in rc4 - any idea

[sqlalchemy] Re: 0.5.0rc3 - kinterbasdb.ProgrammingError: (0, 'Invalid cursor state. The cursor must be open to perform this operation.')

2008-11-10 Thread Michael Bayer
I know what this is and it should be working in r5280. I don't have access to firebird here so we weren't able to run the tests on it before rc3 was out. On Nov 10, 2008, at 7:39 AM, Werner F. Bruhin wrote: I am getting sometimes the following exception with rc3 which I did not see

[sqlalchemy] Re: 0.5.0rc3 - kinterbasdb.ProgrammingError: (0, 'Invalid cursor state. The cursor must be open to perform this operation.')

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 12:10 PM, Werner F. Bruhin wrote: Michael, Michael Bayer wrote: I know what this is and it should be working in r5280. I don't have access to firebird here so we weren't able to run the tests on it before rc3 was out. Thanks for the quick reply. Looking at the

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 10:05 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: Actually, the section after that (Using Subqueries) probably does something very close to what you want. What's the result of these lines: q1 = (session.query(Snapshot.strategy, Snapshot.symbol, sum_pnl)

[sqlalchemy] Re: problem with join, count on 0.5.0rc3

2008-11-10 Thread Michael Bayer
it should be fine. On Nov 10, 2008, at 6:34 AM, Cito wrote: The new behavior is exactly what I expect, namely that query.count() returns the same as len(query.all()). Are there cases in which this does not make sense or where this would not work? -- Christoph

[sqlalchemy] Re: Session and postgres_returning

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 8:37 AM, paftek wrote: Hi, I am using SQLAlchemy with PostgreSQL 8.3. Today I just discovered the great postgres_returning functionnality. Dumb question : Is it possible to take advantage of it in session mode ? In other words, is it possible for session.add() to

[sqlalchemy] 0.5.0rc3 - kinterbasdb.ProgrammingError: (0, 'Invalid cursor state. The cursor must be open to perform this operation.')

2008-11-10 Thread Werner F. Bruhin
I am getting sometimes the following exception with rc3 which I did not see with rc2 when I do something like this: engine = sa.create_engine(dburl, encoding='utf8', echo=False) # connect to the database ##connection = engine.connect() Session = sao.sessionmaker()

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of John Hunter Sent: 08 November 2008 05:09 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: select where field=max(field) [SNIP] Here is a query that lists the sum(pnl) for each

[sqlalchemy] Re: Removing aggregate function from query results

2008-11-10 Thread Ian Charnas
Simon, Michael, thank you! Simon, yes you were totally right, my query was totally wrong! I was up all night trying to get some code working, and at 5am I was getting a little fuzzy. I'd like to use that as my excuse ;-) What I ended up doing this morning was doing a simple query with max and

[sqlalchemy] Re: default=0.0 on Float Column produces `col` float default NULL

2008-11-10 Thread jason kirtland
With 0.4 it's a positional argument to Column: Column('col', Float(), PassiveDefault('0.0')) Simon wrote: Thanks Jason! Is there any way of doing this in SA 0.4 as well? On 10 Nov., 16:42, jason kirtland [EMAIL PROTECTED] wrote: Simon wrote: Hi all, I'm using SA 0.5.0rc3 and MySQL

[sqlalchemy] 0.5rc3 problem (works in 0.5rc2 and 0.4.8)

2008-11-10 Thread David Gardner
Had a problem this morning where SA 0.5rc3 was returning None, while 0.5rc2 and 0.4.8 returned the expected object/row. tables mappers: -- typehierarchy_table = Table('typehierarchy', metadata, autoload=True) typehierarchy_names_table =

[sqlalchemy] extending pre-existing tables

2008-11-10 Thread rdmurray
I sent this last week but it seems like it may not have been posted to the list...at least, I haven't seen any responses :) -- Forwarded message -- Date: Tue, 4 Nov 2008 18:00:57 -0500 (EST) From: [EMAIL PROTECTED] To: sqlalchemy@googlegroups.com Subject: extending pre-existing

[sqlalchemy] Re: extending pre-existing tables

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 3:42 PM, [EMAIL PROTECTED] wrote: Right now I'm playing with mapper inheritance. The first stumbling block I've come to is the case where the local table doesn't yet have a row for the object from the base table. In that case, a query on my subclassed object returns

[sqlalchemy] Re: 0.5rc3 problem (works in 0.5rc2 and 0.4.8)

2008-11-10 Thread Michael Bayer
Hi David - One thing I notice is that your remote_side on the self referential relation from TypeNode-Children is not needed, whereas it *is* needed on the TypeNode-Parent side, which is the many to one side, using backref=backref('Parent', remote_side=[typehierarchy_table.c.id]).

[sqlalchemy] Re: extending pre-existing tables

2008-11-10 Thread rdmurray
On Mon, 10 Nov 2008 at 17:19, Michael Bayer wrote: Possibly. The fragility here is that you are relying on a model that isn't actually implemented here, i.e. that your application is written around a table inheritance assumption when that is not actually the case - the extended tables may or

[sqlalchemy] Re: 0.5rc3 problem (works in 0.5rc2 and 0.4.8)

2008-11-10 Thread David Gardner
Yeah, I kinda figured that out in a round-about way, because 0.5rc2 and 0.4.8 would get me my object, but then node.Parent was the collection of children. Thanks for the response. Michael Bayer wrote: Hi David - One thing I notice is that your remote_side on the self referential relation

[sqlalchemy] Re: 0.5rc3 problem (works in 0.5rc2 and 0.4.8)

2008-11-10 Thread David Gardner
I ended up having problems with my backref (in any version of SA) so I re-worked my mappers and now 0.5rc3 is generating correct SQL. So this probably isn't a bug. mapper(TypeNode, typehierarchy_table, properties={ 'AutoPopNames':relation(TypeAutoPop, backref='TypeNode'),

[sqlalchemy] AttributeError: 'NoneType' object has no attribute 'pop'

2008-11-10 Thread arashf
Traceback (most recent call last): File /srv/server/metaserver/metaserver/lib/base.py, line 56, in __call__ ret = WSGIController.__call__(self, environ, start_response) File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/ controllers/core.py, line 195, in __call__ after =

[sqlalchemy] Re: extending pre-existing tables

2008-11-10 Thread Michael Bayer
On Nov 10, 2008, at 5:34 PM, [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 at 17:19, Michael Bayer wrote: Possibly. The fragility here is that you are relying on a model that isn't actually implemented here, i.e. that your application is written around a table inheritance assumption when

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 11:10 AM, Michael Bayer [EMAIL PROTECTED] wrote: you need an extra tuple on the join, query.join((q1, s.s==q1.c.s)) This gets past the syntax error, but does not produce the right results. I had to take some time off today to work on other problems, but am now

[sqlalchemy] Re: AttributeError: 'NoneType' object has no attribute 'pop'

2008-11-10 Thread Michael Bayer
yeah this is an enhancement we made, whereby InstanceState removes circular references from itself when its host object is garbage collected, thereby taking the load off of gc (and it does). So in this case, asynchronous gc is occurring right as InstanceState is doing expire_attributes

[sqlalchemy] Re: AttributeError: 'NoneType' object has no attribute 'pop'

2008-11-10 Thread arashf
gotcha, cool. was I first to run into this? :-) On Nov 10, 5:57 pm, Michael Bayer [EMAIL PROTECTED] wrote: yeah this is an enhancement we made, whereby InstanceState removes   circular references from itself when its host object is garbage   collected, thereby taking the load off of gc (and

[sqlalchemy] Re: Postgres - Backup - Restore

2008-11-10 Thread Petr Kobalíček
Hi Chris, yeah these tools works great, our problem was that if I did backup and restoration from web interface then this problem happen. I wasn't also familiar with postgres :) Cheers - Petr 2008/11/10 Chris Miles [EMAIL PROTECTED]: On Nov 10, 4:57 am, Petr Kobalíček [EMAIL PROTECTED]