"Kevin Dangoor" <[EMAIL PROTECTED]> writes:

> I'm using sqlite as a temporary store for flattened report database
> (generally just one table). This data is pulled out in chunks using
> OFFSET and LIMIT. This particular setup is quite simple... just insert
> all of the data, and then pull it out chunk by chunk afterwards.
>
> What I'm wondering about is whether I should put an integer primary
> key on the data table to ensure that the ordering is correct, or if
> "SELECT * FROM <table> LIMIT <x> OFFSET <y>" will reliably return data
> in the same order in which is was inserted. It seems to, but I'd
> rather not take that for granted...

Although the order may be the same each time you retrieve the data, that could
change with a future version of sqlite.  I believe that the SQL spec doesn't
specify the order of returned rows if you don't specify an order.

You needn't add an integer primary key, however.  There's already one there
for you to use.  Just change your query to this, and you'll be guaranteed of
the order:

  SELECT * FROM <table> ORDER BY ROWID LIMIT <x> OFFSET <y>

Given that you're inserting the data into the table and then selecting from it
all in the same session, you'd likely have no problem, but it's not necessary
to take that chance.

Cheers,

Derrell

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to