Re: viewing the original (chrnological) order of entered records
| От | Mattias Kregert |
|---|---|
| Тема | Re: viewing the original (chrnological) order of entered records |
| Дата | |
| Msg-id | 030901c32f37$fdc5a0c0$09000a0a@kregert.se обсуждение исходный текст |
| Ответ на | viewing the original (chrnological) order of entered records ("Sven Van Acker" <Sven.Van.Acker@vub.ac.be>) |
| Список | pgsql-general |
Solution #1:
Add a column to hold the time of entry:
ALTER TABLE life ADD COLUMN (entered_at timestamp); -- time of insert
ALTER TABLE life ALTER COLUMN entered_at DEFAULT now(); -- add it automagically
Then you can sort on this column, even if you don't select it for output (order by person_id, entered_at).
Disadvantage: Takes some extra space on disk. Use "WITHOUT OIDS" when creating the table to save some space.
Solution #2:
Use the OID of the row in the ORDER BY (order by person_id, oid). The OID is incremented for every row inserted.
Disadvantages:
This is unsafe, since it will fail when oid's wrap (after 2 billion inserts). That might not be a problem other than in theory :)
You cannot use "WITHOUT OIDS".
/Mattias
----- Original Message -----
From: Sven Van AckerSent: Tuesday, June 10, 2003 11:50 AMSubject: [GENERAL] viewing the original (chrnological) order of entered recordsHi
Ive the following problem:
I have a 2-column table with columns person_id(int4) and phase(text).
When I entered the following records in a chronological fashion: <1, high school>; <1, childhood> and <2, university>;
I requested the following select-statement.
SELECT person_id, phase FROM life ORDER BY person_id
And found the tuple <1, childhood> before the tuple <1, high school>.
I want to view the chronological order of my entries, but ordered by person_id.
Is this possible in postgresql?
В списке pgsql-general по дате отправления: