Re: [sqlalchemy] limit in context of entities not rows

2019-07-04 Thread Simon King
I would first figure out how you would do this in SQL, and then translate that to SQLAlchemy. In this case, the EXISTS operator might work: SELECT * FROM department WHERE EXISTS ( SELECT 1 FROM employee WHERE employee.department_id = department.id AND employee.name IN (...) ) LIMIT

[sqlalchemy] limit in context of entities not rows

2019-07-04 Thread Victor Olex
Using ORM querying what is the best practice for limiting the output to a given number of resulting *entities*? Consider this model: from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import

Re: [sqlalchemy] LIMIT the number of children in relationship dynamically

2017-05-02 Thread mike bayer
On 05/02/2017 12:38 AM, Isaac Martin wrote: Thank you very much for your response. This solution isn't working for me, and I'm 99% sure I'm not translating what you've written into something that works for my use case. My situation is somewhat more complicated than I initially wrote. My first

Re: [sqlalchemy] LIMIT the number of children in relationship dynamically

2017-05-01 Thread Isaac Martin
Well that was a very silly mistake. End of the day oversight is what happened here. I didn't notice that "offset" was set to 10 and my unit test only had 2 values. When I set offset to 0 it worked great. Sincerest thanks for this! I hadn't seen as_scalar used before. I'm looking forward to trying

Re: [sqlalchemy] LIMIT the number of children in relationship dynamically

2017-05-01 Thread Isaac Martin
Thank you very much for your response. This solution isn't working for me, and I'm 99% sure I'm not translating what you've written into something that works for my use case. My situation is somewhat more complicated than I initially wrote. My first question was in the vain hope that there was some

Re: [sqlalchemy] LIMIT the number of children in relationship dynamically

2017-05-01 Thread mike bayer
On 05/01/2017 08:05 PM, Isaac Martin wrote: I am building an api which can return children of resources if the user requests it. For example, |user| has |messages|. I want the query to be able to limit the number of |message| objects that are returned. I found a useful tip about limiting t

[sqlalchemy] LIMIT the number of children in relationship dynamically

2017-05-01 Thread Isaac Martin
I am building an api which can return children of resources if the user requests it. For example, user has messages. I want the query to be able to limit the number of message objects that are returned. I found a useful tip about limiting the number of objects in child collections here

Re: [sqlalchemy] Sybase ASE 15.7 Sqlalchemy Limit/Offset Issue

2014-03-28 Thread Michael Bayer
The Sybase dialect supports rendering of the "TOP" and "START AT" clauses when you use the limit() and offset() constructs of select(). So if you're using Core SQL select() constructs or the ORM Query, it should work at least rudimentally. On Mar 26, 2014, at 4:19 AM, angad nath wrote: > Hi A

[sqlalchemy] Sybase ASE 15.7 Sqlalchemy Limit/Offset Issue

2014-03-28 Thread angad nath
Hi All, I am trying to port my application from MySQL to Sybase ASE 15.7 version. How can i implement my query using LIMIT and OFFSET using sqlalchemy 0.8 targeting Sybase ASE 15.7 ? Thanks, Angad Nath -- You received this message because you are subscribed to the Google Groups "sqlalchemy"

[sqlalchemy] limit and offset for sql execute

2012-06-06 Thread mdob
I've been looking for a way to limit and offset custom sql statement. I can't use query from orm or select with limit and offset methods. I simply get sql string which I execute. q = text(sqlstr) res = session.execute(q).fetchall() I want to have some paging of the result. I've come out with sort

Re: [sqlalchemy] LIMIT function behavior

2010-01-21 Thread Michael Bayer
Kent wrote: > The limit() function behaves in a way that is possibly unexpected: > > If you ask sqlalchemy to query "limit(3)" where a join is involved, > for example, and 2 of the "top-3" are actually the same primary key, > sqlalchemy gets the 3 results, throws out the duplicate and your query >

[sqlalchemy] LIMIT function behavior

2010-01-21 Thread Kent
The limit() function behaves in a way that is possibly unexpected: If you ask sqlalchemy to query "limit(3)" where a join is involved, for example, and 2 of the "top-3" are actually the same primary key, sqlalchemy gets the 3 results, throws out the duplicate and your query size ends up as 2. Thi

[sqlalchemy] limit

2009-05-05 Thread Tiago Becker
Hello. I'm trying to write some kind of framework web, but i would like to use sqlalchemy, but i need to make a paged result, and every DB has a way to limit the query... Is there a way to do this in alchemy? Note: it's a query defined in xml, so i use pure sql (this part will just use the alchem

[sqlalchemy] Limit invalidates query results on view - 0.4.8

2009-03-17 Thread Jonathan Vanasco
I have query on a view that looks like this: query= dbSession.query(_class).filter('entry_status = 2').order_by ( _class.c.entry_authored_on.desc() ).limit(3).offset(0) results= query.all() print query print " - - - - - -" print results print "== == ==" this always returns no results. howe

[sqlalchemy] limit the set of returned columns

2008-10-07 Thread Martijn Moeling
Hi, Yesterday I was searching this group and the SA 5.0 doc to get something working. Somewere I came across an option to specify the columnames to return (and getting a tuple or so) Let me explain: Keep the following in mind: I have a table which stores files defined with Declarat

[sqlalchemy] Limit to 500 records after particular date.

2008-09-24 Thread Heston James - Cold Beans
Morning Guys, I hope this'll be a fairly simple question. I have a query which looks something like this: the_objects = session.query(myobject.myobject).filter("myobject.created > :lastrecord").params(lastrecord=time.strftime("%Y-%m-%d %H:%M:%S", from_date)).all() This grabs all the rec

[sqlalchemy] LIMIT in queries

2007-12-12 Thread Felix Schwarz
Hi, after reading the docs [1] I thought that something like session.query(User).filter(User.c.id > 3)[0] should work even if the filter clause does not return any rows. But - compliant with Python's behavior - SQLAlchemy raises an IndexError. (...) File "/usr/lib/python2.4/site-packages/sqla

[sqlalchemy] LIMIT in update()

2007-10-16 Thread Jim Musil
Hi, I'm trying to determine a way to append a LIMIT to an update() object. Is the solution a correlated update on the same table with the LIMIT on the select() object? Cheers, Jim --~--~-~--~~~---~--~~ You received this message because you are subscribed to t

[sqlalchemy] LIMIT syntax in old versions of MySQL

2007-09-20 Thread King Simon-NFHD78
Hi, The ancient version of MySQL that I am connecting to (3.23.58) doesn't support the syntax 'LIMIT OFFSET ' syntax. Instead, it uses LIMIT , . This is described in the docs, but it doesn't say what version introduced the more standard syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html

[sqlalchemy] limit=bindparam("result_limit")

2007-09-18 Thread dykang
Hi, I was trying to write a query where the limit clause was actually a bind param, however it appears that, (in 3.10), this isn't possible. Am I missing something, or is this a bug? for example I'm just doing s = select ([Table], whereclause, limit=bindparam('mylimit')) s.execute(mylimit=5) C

[sqlalchemy] Re: sqlalchemy limit by clause

2007-04-16 Thread svilen
default of limit is None. All those query.select arguments go in a orm.query.QueryContext() do see its __init__ for which arg has what default. On Tuesday 17 April 2007 09:31:04 Disrupt07 wrote: > I am defining my result list the following way: > > result = queryobject.select(mytable.c.columnname

[sqlalchemy] sqlalchemy limit by clause

2007-04-16 Thread Disrupt07
I am defining my result list the following way: result = queryobject.select(mytable.c.columnname == columnname, limit = maxResults, offset = 0) maxResults is the number of records I want returned. In case I want all the records, I am setting maxResults as -1. However, this is not working for m