Re: viewing the original (chrnological) order of entered records - Mailing list pgsql-general

From Mattias Kregert
Subject Re: viewing the original (chrnological) order of entered records
Date
Msg-id 030901c32f37$fdc5a0c0$09000a0a@kregert.se
Whole thread Raw
In response to viewing the original (chrnological) order of entered records  ("Sven Van Acker" <Sven.Van.Acker@vub.ac.be>)
List 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 -----
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?

pgsql-general by date:

Previous
From: Csaba Nagy
Date:
Subject: Re: viewing the original (chrnological) order of entered
Next
From: "Ned Lilly"
Date:
Subject: Re: [pgsql-advocacy] MySQL gets $19.5 MM