Den 18/06/2014 kl. 14.31 skrev Glen Jungels <glenjung...@gmail.com>:

> It will be different depending on the database (assuming you are asking about 
> the query only).  You will need to do an order by on either your auto 
> incremented field or dat field plus something like a limit 2 (Postgres and I 
> believe MySQL) or top 2 for something like SQL Server.

Interestingly, the question is very simple, but the answer is very complicated 
if you simply *must* get the exact answer.

Databases don't make any promises on the order of the rows returned unless a 
specific order clause is provided. auto_increment sequences can be reset and 
primary keys can be reused, so you can't necessarily order by primary key. 
Result limits are implemented very differently depending on the database vendor 
since LIMIT is not part of the SQL standard (see 
http://en.wikipedia.org/wiki/Select_(SQL)#Result_limits), and your database 
backend might not even support it.

Finally, using an 'insert_date' field only works if the precision of the column 
type is significantly lower than the rate of insertion. E.g. MySQL <= 5.5 only 
has second precision for the DATETIME type and wouldn't be useful if you have 
10 inserts per second.

Erik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A9576EA4-D3D5-4E5E-836E-0B5CE450FBE2%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to