Friday, June 6, 2008

[GENERAL] accessing table in LIFO order

I have got a table that holds 2 columns: date_id and info. date_id is bigint, created as, for eg. 17 May 2008, 19:05 hrs => 200805171905. This table is populated with {date, info} pair that I receive frequently. AND there can be mltiple such entries with a single date_id but varying info, for eg. 20 entries with same date_id but different info. I haven't created any primary key or index.

I use query that looks like this:
SELECT date_id, info FROM netproto_entries ORDER BY date_id DESC LIMIT <limit_val>;

Questions:
- For higher values of limit_val (say 70/75/..), when I change it, the order
  in which I get the entries changes. Eg. it shows me one info at the top at
  one time, and another on the next time with a different value of limit_val.

- My intent is to fetch the entries from the database in LIFO order, most
  recently entered entry at the top. For the elements with the date_id being
  the same, they are not in LIFO order. I understand that I can add another
  incrementing index column and sort the table based on that. But, without adding this,
  does postgresql have any method/configuration to get me output in LIFO order ?
  And are there any better methods available compared to adding another index
  column (as mentioned above) ?

Thanks,
Ethan

No comments: