[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Alexandre CONRAD
Michael Bayer wrote: I've implemented all the missing class-level methods on ScopedSession in r3212, so you should be able to call refresh(). Great, thanks. I'll check this out. But also, if you want to say Session(), then work with it, that is also the intended usage model, although

[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Alexandre CONRAD
Alexandre CONRAD wrote: Don't forget to answer my question: What are the benefits of instantiating a Session object ?. Actually, I just feel better working *with* a instantiated object. Hey, I just set my code to instantiate the session, and I get the following error when I delete a

[sqlalchemy] Re: Using SA to move data between databases

2007-08-09 Thread Paul Johnston
Hi, A little update; this code handles the case where columns have a key attribute: model = __import__(sys.argv[1]) if sys.argv[2] == 'copy': seng = create_engine(sys.argv[3]) deng = create_engine(sys.argv[4]) for tbl in model.metadata.table_iterator(): print tbl

[sqlalchemy] Problem with .count() on a query that works

2007-08-09 Thread mattrussell
Hi, I have query which works which joins two tables together (Am using elixir and tesla trunks, SA 0.3.10): q = model.Thing.query() q = q.add_entity(model.OtherThing) q = q.filter(my_filter_expr) q.all() This executes fine. but doing: q.count() (Am trying to use webhelpers.paginate) , class

[sqlalchemy] NULLS FIRST/LAST support?

2007-08-09 Thread SOS
I notice there is no support for the NULLS FIRST/NULLS LAST specifier on ORDER BY clauses. Am I overlooking something or is this really the case? Is there any chance of support for this coming soon? Or is it too vendor-specific to be in SQLAlchemy? If it is feasible, has anyone created a

[sqlalchemy] Re: Problem with .count() on a query that works

2007-08-09 Thread mattrussell
This is my error. I'm creating a custom Column object (via subclassing), because I want to override operator behaviour for .in_ to provide geometry support to a column. I must of missed something in implementing the column subclass. Currently, I'm just returning a string from the in_( method of

[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Michael Bayer
On Aug 9, 2007, at 3:59 AM, Alexandre CONRAD wrote: But also, if you want to say Session(), then work with it, that is also the intended usage model, although the Session.xxx methods should in theory be all you need. Why should I instantiate session = Session() if everything off the

[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Michael Bayer
On Aug 9, 2007, at 4:12 AM, Alexandre CONRAD wrote: Alexandre CONRAD wrote: Don't forget to answer my question: What are the benefits of instantiating a Session object ?. Actually, I just feel better working *with* a instantiated object. Hey, I just set my code to instantiate the

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-09 Thread Michael Bayer
i was totally guessing mysql on this one...but its oracle ! who knew. you're free to just use a string and say order_by=somecolumn NULLS FIRST on this. we could add an operator to the oracle module if that helps, something like (assume 0.4 usage)

[sqlalchemy] Question about queries and operators

2007-08-09 Thread mattrussell
Hi, related to my recent post on subclassing Column: The problem I have is that the right tables are not appearing in the FROM list in the query. I have overriden the 'in_' operatror on the column. When calling 'all()' on my query instance, I get the result back as I expected, but when calling

[sqlalchemy] Re: Question about queries and operators

2007-08-09 Thread Michael Bayer
add_entity() by itself is not going to add a table to a count() function; the extra entities arent taken into account by count(). Looking at the query you have below, i.e. the one which works, im a little puzzled. you aren't associating the geo_route and geo_location tables together

[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Alexandre CONRAD
Michael Bayer wrote: Hey, I just set my code to instantiate the session, and I get the following error when I delete a client (which has a bunch of cascading all, delete-orphan rules). session = Session() NB: I've mapped the session.delete function to my model object for convenience:

[sqlalchemy] PATCH for SQLAlchemy mangling of dollar sign identifiers

2007-08-09 Thread Brandon Craig Rhodes
SQLAlchemy mangles identifiers that have dollar signs in them; in particular, the regular expression in ANSICompiler.after_compile() that searches a statement for positional parameters will take a parameter like :foo$bar and only snatch the foo out of it, instead of foo$bar. The error that

[sqlalchemy] Problem with subquery

2007-08-09 Thread Jeronimo
Greetengs, i tried to solve the problem using different approaches but none of them worked. Here are the examples using both, plain SQL and SQLALchemy methods. * Using plain SQL: create table node(id integer, parent_id integer, type_id integer); insert into node(1,NULL,1); insert into node

[sqlalchemy] Problem with subquery

2007-08-09 Thread Jeronimo
Greetengs, i tried to solve the problem using different approaches but none of them worked. Here are the examples using both, plain SQL and SQLALchemy methods. * Using plain SQL: create table node(id integer, parent_id integer, type_id integer); insert into node(1,NULL,1); insert into node

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-09 Thread Oleg Deribas
Hello, Michael Bayer said the following on 09.08.2007 17:09: we could add an operator to the oracle module if that helps, something like (assume 0.4 usage) order_by=oracle.nullsfirst(mycolumn.desc()) , i guess that is important if youre applying ordering to relations which get

[sqlalchemy] Re: refresh() with scoped_session ?

2007-08-09 Thread Michael Bayer
On Aug 9, 2007, at 11:43 AM, Alexandre CONRAD wrote: So I prepared a test case in a single file, but it works in both cases. My problem is in my Pylons app, and I suspect that the dispersed modules doing imports are making some trouble (session instantiated in a module, then

[sqlalchemy] Re: PATCH for SQLAlchemy mangling of dollar sign identifiers

2007-08-09 Thread Michael Bayer
thanks, i put this in ticket 719 so that someone can patch it. On Aug 9, 2007, at 12:20 PM, Brandon Craig Rhodes wrote: SQLAlchemy mangles identifiers that have dollar signs in them; in particular, the regular expression in ANSICompiler.after_compile() that searches a statement for

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Michael Bayer
if youre on 0.3, you can explicitly correlate to n1 by saying: myselect.correlate(n1) also in 0.3, it would probably help to say scalar=True in your select() statement (and you dont need the alias): n1 = node_table.alias('n1') sub_query = select([func.max(node_table.c.id).label('max_id')],

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-09 Thread Michael Bayer
ah that changes things...if NULLS FIRST/LAST is part of ANSI sql then id feel comfortable adding a core construct, like order_by=column.nullsfirst(). On Aug 9, 2007, at 12:27 PM, Oleg Deribas wrote: Hello, Michael Bayer said the following on 09.08.2007 17:09: we could add an operator

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Jeronimo
I'm using version 0.3.9 with PostgresSQL 8.1 . Because postgres needs aliased subqueries i changed the example code you sent to: n1 = node_table.alias('n1') sub_query = select([func.max(node_table.c.id).label('max_id')], (node_table.c.type_id==n1.c.type_id), scalar=True) sub_query.correlate(n1)

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Jeronimo
I cant manage to make sub_select appear at WHERE level, it always appears at FROM level. The SQL statement needs to select one node for each type, and each node must be the one with the max id in that type. Is it possible to make this statement using SQLAlchemy ? On Aug 9, 6:11 pm, Jeronimo

[sqlalchemy] Automatic converter from latin1 to Unicode

2007-08-09 Thread Hermann Himmelbauer
Hi, I am writing a web application which retrieves data through SQLAlchemy. Character-based data in this database is encoded as latin1. My Web-framework (Zope3) expects strings in the unicode format and throws errors like this: UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-09 Thread Oleg Deribas
Hello, Michael Bayer said the following on 09.08.2007 20:50: ah that changes things...if NULLS FIRST/LAST is part of ANSI sql then id feel comfortable adding a core construct, like order_by=column.nullsfirst(). Here is what I've found in SQL2003 draft: In addition, NULLS FIRST or NULLS

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-09 Thread Michael Bayer
OK just to double check, the syntax looks like: SELECT * FROM sometable ORDER BY foo NULLS FIRST SELECT * FROM sometable ORDER BY foo DESC NULLS LAST ? i.e. is DESC/ASC before the NULLS part ? or doesn't matter ? we can add this to 0.4.

[sqlalchemy] Re: I can't use YEAR column type with sqlalchemy/databases/mysql.py

2007-08-09 Thread jason kirtland
hiroshiykw wrote: Hi. In SQLAlchemy 0.3.10 ( / Python2.5), I found that YEAR column type is created as TEXT column type in the following [...] Sorry about that. This is now fixed in the trunk for 0.4 and in the 0.3 maintenance branch. Cheers, Jason

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Michael Bayer
OK sorry, i didn't look carefully enough. when you use a scalar subquery, you shouldn't access the c attribute on it. I hadn't really realized that and maybe i should add an exception for that. when you access the c attribute, you're treating it like another relation to be selected from, so it

[sqlalchemy] Re: Question about queries and operators

2007-08-09 Thread mattrussell
Hi Michael, I've sorted this one now :) I'm sorry for the amigious nature of my post... wasn't clear in my head at the time. You are right, I wasn't associating between the two entities in the example I gave. I ended up using sqlalchemy.sql._BinaryExpresssion in my subclass, which enabled the

[sqlalchemy] Re: Automatic converter from latin1 to Unicode

2007-08-09 Thread Michael Bayer
absolutely, see the docs on the create_engine() argument convert_unicode here: http://www.sqlalchemy.org/docs/03/dbengine.html#dbengine_options and the docs on the Unicode datatype here: http://www.sqlalchemy.org/docs/03/types.html any string type also accepts a flag convert_unicode=True. so

[sqlalchemy] Re: Question about queries and operators

2007-08-09 Thread Michael Bayer
hey matt - you might also look at a new feature we have in 0.4 called composite column types, this is an ORM-only feature whereby you can provide column-behavior on a plugin basis and also use multiple columns to represent a single scalar unit:

[sqlalchemy] new session docs !

2007-08-09 Thread Michael Bayer
hey gang - the last big page of the docs that i wanted to get out for 0.4 is *mostly* complete, i just need to write about the ever-controversial scoped_session() function and a little more about partitioning. the doc is a lot more friendly than the previous doc and has shed most of the

[sqlalchemy] Re: Query and efficient on-demand loading of all rows

2007-08-09 Thread Boris DuĊĦek
Hi Mike, thank you so much for such an extensive answer. It has provided me with much better insight about the topic, so that I can now make a qualified decision on how to proceed. Best regards, Boris On Aug 6, 8:39 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 6, 2007, at 10:42 PM, Boris