From: | "Mattias Kregert" <mattias(at)kregert(dot)se> |
---|---|
To: | "Sven Van Acker" <Sven(dot)Van(dot)Acker(at)vub(dot)ac(dot)be> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: viewing the original (chrnological) order of entered records |
Date: | 2003-06-10 10:06:41 |
Message-ID: | 030901c32f37$fdc5a0c0$09000a0a@kregert.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 Acker
To: pgsql-general(at)postgresql(dot)org
Sent: Tuesday, June 10, 2003 11:50 AM
Subject: [GENERAL] viewing the original (chrnological) order of entered records
Hi
I've 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?
From | Date | Subject | |
---|---|---|---|
Next Message | Csaba Nagy | 2003-06-10 10:06:49 | Re: viewing the original (chrnological) order of entered |
Previous Message | Nigel J. Andrews | 2003-06-10 10:02:31 | Re: host and hostssl equivalence in pg_hba.conf |