Re: Re: Order question - Mailing list pgsql-general

From Lamar Owen
Subject Re: Re: Order question
Date
Msg-id 3A89C20A.E1226E86@wgcr.org
Whole thread Raw
In response to Order question  ("Mitch Vincent" <mitch@venux.net>)
List pgsql-general
Mitch Vincent wrote:
>
> A further extension of this..
>
> What might I be able to additionally order by so that the most recently
> updated rows get ordered above everything else (within the order by
> ordernum).. Using the same example :
>
> >  ordernum |   fieldname   |   oid
> > ----------+---------------+---------
> >         1 | J.jobtitle    | 1197126
> >         1 | J.inv_id      | 1197125
> >         2 | J.updatedon   | 1197127
> >         3 | J.empinitials | 1197128
>
> I just set the row with j.inv_id to 1, I'd like it to be ordered above the
> row with j.jobtitle in it -- is that possible?

Add a column with a timestamp.  Then, in the update/insert, make the
timestamp equal the current time.  Then ORDER BY ordernum, timestamp.

Or better, modify the other ordernums, as you have an ambiguous
situation with two ordernums being equal. Writing that in a single
UPDATE would be left as an exercise for the reader :-).
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11

pgsql-general by date:

Previous
From: Mike Castle
Date:
Subject: Re: Re: Order question
Next
From: Tom Lane
Date:
Subject: Re: psql segfault