Re: [sqlalchemy] how to get last record from a resultset

2011-07-20 Thread Timuçin Kızılay

I think, reversing the sort and getting the first record will do.



20-07-2011 16:32, Krishnakant Mane yazmış:

Hello all,
Subject line says it all.
Basically what I want to do is to get last record from a result set.
I am dealing with a situation where given a date I need to know the last
record pertaining to transaction on a given account.
yes, it is an accounting/ book keeping software.
So I thought there was some thing like .last() method for a resultset?
Or even better do we have some thing like session.query(table).last()
The problem is that my logic is in place but I know that performance
wise it is very dirty to get the list of all records, just to loop till
the end and throw away all the rest of the rows.
So plese suggest how can I only get just that one (last) record?
Happy hacking.
Krishnakant.



--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] how to get last record from a resultset

2011-07-20 Thread Krishnakant Mane
Well, there won't be a consistent result using sort because there might 
be 10 rows with same voucher code and same account code.

That's exactly the challenge so I don't know how sort will help.
If we can invert the entire resultset having the last record become 
first,  then its worth while.

But again, I don't want the entire set of rows in the first place.
I just want that particular row.
Happy hacking.
Krishnakant.

On 20/07/11 19:20, Timuçin Kızılay wrote:

I think, reversing the sort and getting the first record will do.



20-07-2011 16:32, Krishnakant Mane yazmış:

Hello all,
Subject line says it all.
Basically what I want to do is to get last record from a result set.
I am dealing with a situation where given a date I need to know the last
record pertaining to transaction on a given account.
yes, it is an accounting/ book keeping software.
So I thought there was some thing like .last() method for a resultset?
Or even better do we have some thing like session.query(table).last()
The problem is that my logic is in place but I know that performance
wise it is very dirty to get the list of all records, just to loop till
the end and throw away all the rest of the rows.
So plese suggest how can I only get just that one (last) record?
Happy hacking.
Krishnakant.





--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



RE: [sqlalchemy] how to get last record from a resultset

2011-07-20 Thread King Simon-NFHD78
If you don't have something consistent to sort by, then I'm not sure that the 
last record is meaningful, is it? If you have 10 rows with the same voucher 
code and account code (and there is nothing else to uniquely identify them, 
such as a more precise timestamp, or an auto-incrementing ID), then as far as 
the result set is concerned, there is nothing special about the last row. The 
database could be giving them to you in any order.

I'm sure I'm misunderstanding your situation - perhaps you could describe your 
schema and why you need this information, and then we might be more help.

Simon

 -Original Message-
 From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
 On Behalf Of Krishnakant Mane
 Sent: 20 July 2011 15:16
 To: sqlalchemy@googlegroups.com
 Cc: Timuçin Kızılay
 Subject: Re: [sqlalchemy] how to get last record from a resultset
 
 Well, there won't be a consistent result using sort because there
 might
 be 10 rows with same voucher code and same account code.
 That's exactly the challenge so I don't know how sort will help.
 If we can invert the entire resultset having the last record become
 first,  then its worth while.
 But again, I don't want the entire set of rows in the first place.
 I just want that particular row.
 Happy hacking.
 Krishnakant.
 
 On 20/07/11 19:20, Timuçin Kızılay wrote:
  I think, reversing the sort and getting the first record will do.
 
 
 
  20-07-2011 16:32, Krishnakant Mane yazmış:
  Hello all,
  Subject line says it all.
  Basically what I want to do is to get last record from a result
 set.
  I am dealing with a situation where given a date I need to know
 the last
  record pertaining to transaction on a given account.
  yes, it is an accounting/ book keeping software.
  So I thought there was some thing like .last() method for a
 resultset?
  Or even better do we have some thing like
 session.query(table).last()
  The problem is that my logic is in place but I know that
 performance
  wise it is very dirty to get the list of all records, just to loop
 till
  the end and throw away all the rest of the rows.
  So plese suggest how can I only get just that one (last) record?
  Happy hacking.
  Krishnakant.
 
 
 
 --
 You received this message because you are subscribed to the Google
 Groups sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.