[sqlalchemy] Re: ordering list: list order not updated on delete (orm)

2009-07-08 Thread wobsta
Hi, just for the records: I've came up myself with an alternative solution to store an ordered list. The basic idea is to calculate order keys from a set of characters such that I can always insert items in front of the list and at the end of the list and also between any two items. I never need

[sqlalchemy] Re: ordering list: list order not updated on delete (orm)

2009-07-06 Thread Michael Bayer
wobsta wrote: > > On 4 Jul., 17:05, Michael Bayer wrote: >> remove the item using remove().  What's the "items must be in a list   >> rule", the not nullable foreign key ?  thats what "delete-orphan"   >> cascade is for, its in the tutorial and reference documentation. > > Thanks, this works for

[sqlalchemy] Re: ordering list: list order not updated on delete (orm)

2009-07-06 Thread wobsta
On 4 Jul., 17:05, Michael Bayer wrote: > remove the item using remove().  What's the "items must be in a list   > rule", the not nullable foreign key ?  thats what "delete-orphan"   > cascade is for, its in the tutorial and reference documentation. Thanks, this works for the simple case in my fi

[sqlalchemy] Re: ordering list: list order not updated on delete (orm)

2009-07-04 Thread Michael Bayer
On Jul 4, 2009, at 2:21 AM, wobsta wrote: > > Hi, > > in my following example I don't know how to properly delete items in > an ordered list. I can't call items.remove (as I would violate the > "items must be in a list rule"). remove the item using remove(). What's the "items must be in a list

[sqlalchemy] Re: Ordering results of a WHERE x in y query by y

2009-02-26 Thread Gunnlaugur Thor Briem
Thanks. But using a CASE clause becomes objectionable in exactly those cases where I would want to have the DB do the sorting — i.e. where the table is big enough that just sorting the result set in python code using array index (rows.sort(key=lambda row: values.index(row[0]))) would be a Bad Thing

[sqlalchemy] Re: Ordering results of a WHERE x in y query by y

2009-02-26 Thread Ants Aasma
import sqlalchemy def index_in(col, valuelist): return sqlalchemy.case([(value,idx) for idx,value in enumerate (valuelist)], value=col) session.query(C).filter(C.someattr.in_(valuelist)).order_by(index_in (C.someattr, valuelist)) Don't try to do this with huge lists of items. On Feb 25, 5:

[sqlalchemy] Re: Ordering query for a list

2009-01-07 Thread az
afaik, this is like traversing a tree, just maybe worse (much bigger length). i would either load them all somehow (unless they are zillions), or create a parasitic named groupings, say list1, list2, list3 and link them via m2m. e.g. list1 links to a1,a2,a4; list 2 links to a6,a5,a7 etc. no id

[sqlalchemy] Re: Ordering null dates

2008-06-10 Thread Cito
Only for the record: I just noticed that another simple workaround is ordering by something like "start_date is not null, start_date, end_date is null, end_date". SA could also implement "nullsfirst()/ nullslast()" that way if the database engine does not support "nulls first/nulls last". --~--~--

[sqlalchemy] Re: Ordering null dates

2008-06-09 Thread Michael Bayer
On Jun 9, 2008, at 12:56 PM, Christoph Zwerschke wrote: > > Michael Bayer wrote: >> I tend to use a CASE statement for this: CASE WHEN x IS NULL THEN 0 >> ELSE x . We have case() construct for that. > > Yes, but that still leaves me with having to code "infinity" some way. > >> For your versi

[sqlalchemy] Re: Ordering null dates

2008-06-09 Thread Christoph Zwerschke
Michael Bayer wrote: > I tend to use a CASE statement for this: CASE WHEN x IS NULL THEN 0 > ELSE x . We have case() construct for that. Yes, but that still leaves me with having to code "infinity" some way. > For your version, use func.coalesce(start, literal_column("timestamp '- > infini

[sqlalchemy] Re: Ordering null dates

2008-06-09 Thread Michael Bayer
On Jun 9, 2008, at 11:34 AM, Christoph Zwerschke wrote: > > I need to order a table by start and end dates, where null values > should > be interpreted as "prior to all values" for start dates and "later > than > all values" for end dates. > > This could be realized with "nulls first", "null

[sqlalchemy] Re: ordering

2008-05-30 Thread Michael Bayer
On May 30, 2008, at 12:25 PM, Geoff wrote: > > Hi! > > I've noticed that a very simple query has an ordering applied to it > even though I haven't asked for one. Is there a way to stop it doing > that? > > the query: > Session.query(User).set_shard(shard).filter_by(uuid=uuid).all() > order_by(N

[sqlalchemy] Re: ordering

2008-05-30 Thread Bobby Impollonia
You can add .order_by(None) to the query to remove the default ordering. On Fri, May 30, 2008 at 12:25 PM, Geoff <[EMAIL PROTECTED]> wrote: > > Hi! > > I've noticed that a very simple query has an ordering applied to it > even though I haven't asked for one. Is there a way to stop it doing > that

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Michael Bayer
OK you got it in r4673, sorry youre hitting all these (kinda weird) On May 6, 2008, at 7:20 PM, Michael Bayer wrote: > > thats really weird. I dont have time to check this now but i added > ticket 1027 to confirm. > > > On May 6, 2008, at 5:22 PM, Moshe C. wrote: > >> I couldn't create a s

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Michael Bayer
thats really weird. I dont have time to check this now but i added ticket 1027 to confirm. On May 6, 2008, at 5:22 PM, Moshe C. wrote: > I couldn't create a simple test case, but I have analyzed the cause of > the problem. > > The order_by() method is sent a list as an argument, but the argu

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Moshe C.
I couldn't create a simple test case, but I have analyzed the cause of the problem. The order_by() method is sent a list as an argument, but the argument 'criterion' becomes a tuple because of the "def order_by(self, *criterion)" syntax. in the case of "if self._aliases_tail:" , 'criterion' beco

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Michael Bayer
On May 6, 2008, at 3:08 PM, Moshe C. wrote: > > Both methods cause a crash (yes, on 0.4.5) . > > converting a tuple to a list in sqlalchemy/orm/query.py fixes it for > one of the methods, for the other you need to do the opposite, convert > a list to a tuple. > > File '/home/moshe/top/webapp/rma

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Moshe C.
Both methods cause a crash (yes, on 0.4.5) . converting a tuple to a list in sqlalchemy/orm/query.py fixes it for one of the methods, for the other you need to do the opposite, convert a list to a tuple. File '/home/moshe/top/webapp/rma/rma/controllers/list.py', line 215 in list_sources myquer

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Michael Bayer
On May 6, 2008, at 1:43 PM, Moshe C. wrote: > > Hi, > > Node is an orm mapped class, which is self-referential. > > myquery = Node.query() > myquery = myquery.join('parent', aliased=True) > myquery = myquery.filter(Node.c.desc.like('%something')) > myquery = myquery.order_by(Node.c.name) > > The

[sqlalchemy] Re: Ordering by related column's related column

2008-02-04 Thread Utku Altinkaya
On Feb 4, 11:03 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Feb 4, 2008, at 3:46 PM, Utku Altinkaya wrote: > > > > > I get it, the result with joins for eager loading has nothing to do > > with sorting. So I have to join them to base selected set to use. But > > I feel like selecting twice

[sqlalchemy] Re: Ordering by related column's related column

2008-02-04 Thread Michael Bayer
On Feb 4, 2008, at 3:46 PM, Utku Altinkaya wrote: > > > > > I get it, the result with joins for eager loading has nothing to do > with sorting. So I have to join them to base selected set to use. But > I feel like selecting twice, is there a peformance penalty here? > > properties = > properties

[sqlalchemy] Re: Ordering by related column's related column

2008-02-04 Thread Utku Altinkaya
On Feb 4, 8:13 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Feb 4, 2008, at 11:29 AM, Utku Altinkaya wrote: > > > > > Greetings, > > > I have Users class with relation to Address which have relation to > > Cities, all are eager loaded. I want to sort the Users query with the > > name field

[sqlalchemy] Re: Ordering by related column's related column

2008-02-04 Thread Michael Bayer
On Feb 4, 2008, at 11:29 AM, Utku Altinkaya wrote: > > Greetings, > > > I have Users class with relation to Address which have relation to > Cities, all are eager loaded. I want to sort the Users query with the > name field of the cities table. But if I order by City.name the cities > table is j

[sqlalchemy] Re: Ordering by field in related object

2007-04-09 Thread Norjee
Thanks a lot!! Grin the Django query object actually allows for this sort of ordering so i just figured SqlAlchemy should allow it as well :/ But never mind now I know the trick it's super easy to adjust for it ;) --~--~-~--~~~---~--~~ You received this message b

[sqlalchemy] Re: Ordering by field in related object

2007-04-08 Thread Arun Kumar PG
Since I am new to SA just want if that means that even if we have an eager load on a 1:N relationships we should still do an explicit JOIN if the query involves columns from both side of relations? On 4/9/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > > eagerly loaded relationships are not part

[sqlalchemy] Re: Ordering by field in related object

2007-04-08 Thread Michael Bayer
eagerly loaded relationships are not part of the main Query criterion/ select. the eager loads are always tacked on secondary to the inner query. the main goal being that if you had lazy or eagerly loaded relationships, in both cases youd get the identical result. so any tables that you

[sqlalchemy] Re: Ordering by field in related object

2007-04-08 Thread Norjee
The generated query is = SELECT verhalen_verhaal.body AS verhalen_verhaal_body, verhalen_verhaal.update_date AS verhalen_verhaal_update_date, verhalen_verhaal.user_id AS verhalen_verhaal_user_id, verhalen_verhaal.review_date AS verhalen_verhaal_review_date, verh

[sqlalchemy] Re: Ordering with the AssociationProxy

2006-11-27 Thread Paul K
Performing an ordered result was simple enough. In the proxied_association.py example, only the following mapper() call was changed: mapper(Order, orders, properties={'itemassociations':relation(OrderItem, cascade="all, delete-orphan", lazy=True, order_by=items.c.description)}) --~--~-

[sqlalchemy] Re: Ordering with the AssociationProxy

2006-11-16 Thread Michael Bayer
theres an example in the distro, in examples/association/proxied_association.py that shows off the creator function as well as the **kwargs idea. its used to provide a customized method of creating the association object. also make sure you understand how to use association objects without this

[sqlalchemy] Re: Ordering with the AssociationProxy

2006-11-16 Thread Paul K
Okay thanks, I'll work some more on it and post my solution. By the way, in looking at the proxied_association.py example, I have another question. When is the creator (callable) function required? If a proxied assocation can be created without a creator function, what additional abilities does

[sqlalchemy] Re: Ordering with the AssociationProxy

2006-11-16 Thread Michael Bayer
this is doable with the proper combination of eager loading between association and remote instance, and the order_by option on the remote relation(). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" gr