in reply to database not in correct order

If this is a table in a MySQL database, I would change the posttime column to be a TIMESTAMP data type. That will remove the need for you to have insert that field.

And as Dragonchild said, you cannot guarantee order in a database without an ORDER BY in your select statement. Primary keys for doing a sort are a bad approach. Do an ORDER BY on the posttime column, especially if you take my advice and have it as a TIMESTAMP.

Replies are listed 'Best First'.
Re^2: database not in correct order
by aquarium (Curate) on Nov 27, 2007 at 05:04 UTC
    yep...as everyone has already indicated, database tables are sets, with no pre-defined time/sequence for results, unless you implement one (using SQL order by). This allows for the notion/use of atomic updates, e.g. (SQL pseudocode) UPDATE TABLE test SET some_time_column TO now()
    All the rows will be set with the same value returned by now() function. "set theory" applies to relational databases, and it breaks if values change over time.
    the hardest line to type correctly is: stty erase ^H
Re^2: database not in correct order
by CountZero (Bishop) on Nov 27, 2007 at 15:24 UTC
    But given the speed at which the records will be included into the database, you are likely to end up with multiple records sharing the same TIMESTAMP value. In my version of MySQL the TIMESTAMP has only a one second granularity.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James