On 11 November 2010 09:17, Jagdeep Singh Malhi <singh.malh...@gmail.com> wrote:
>
> now I also try  another method to get max(id)
>
>    from django.db import connection
>    cursor = connection.cursor()
>    cursor.execute('SELECT max(id) FROM automation_client')
>    maxid = cursor.fetchone()
>
> output is :
> (2L,)
>
> but i want only  2 not any other character.

You have a 1 element tuple with a number. Ig you know anything about
Python, it shouldn't be hard to get that value from the tuple.

>
> Is any other method to get max(id) from database tables?

Starting from version 1.1 Django supports aggregation[1], so you can just write:

>>> from django.db.models import Max
>>> Client.objects.aggregate(maxid=Max('id'))
{'maxid': 2L}

And you'll get a dictionary with the value you want as a result.


[1]: http://docs.djangoproject.com/en/1.1/topics/db/aggregation/

-- 
Łukasz Rekucki

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

Reply via email to