Re: Getting The Last Entry - Mailing list pgsql-novice

From Lew
Subject Re: Getting The Last Entry
Date
Msg-id i6iovt$db7$1@news.albasani.net
Whole thread Raw
In response to Re: Getting The Last Entry  (Luiz Eduardo Cantanhede Neri <lecneri@gmail.com>)
List pgsql-novice
(Top-posting corrected.)

Thom Brown wrote:
>     On 10 September 2010 16:31, Francisco Leovey <fleovey@yahoo.com
>     <mailto:fleovey@yahoo.com>> wrote:
>      >
>      > if by "last" you mean the last row inserted, use
>      >
>      > select *,oid from table order by oid DESC limit 1
>      >
>      > (asuming you use OID's)
>
>     (copying in list with your response)

Luiz Eduardo Cantanhede Neri wrote:
>> Once I suggested to use oid, but some guys here said was a poor design.

It is, but you don't just throw the baby out with the bathwater.  Use the
"ORDER BY ... DESC LIMIT 1" trick with a column that is not bad design, one
that matches your (as yet unrevealed) definition of "last record", as Thom
suggested.

Within themselves tables have no notion of order or "last" vs. "first" other
than the OID.  The reason that OID use is bad is its role as an internal,
DB-only mechanism - it is not connected to the data model and therefore
creates risks that real columns do not.

"It's bad design to use OID" can be countered with, "Yeah, I know, I'm using
it anyway" if you elucidate and ameliorate the risks involved, and show why
the better alternatives (use of a data-model-relevant column to order your
data) cannot be used this time.

But your colleagues do have a point - use the better alternatives unless you
really, really, really, really cannot and are able to fully explain and
justify why not.

Don't let good rules ("Avoid use of the OID") become cargo-cult superstitious
dogma.

--
Lew

pgsql-novice by date:

Previous
From: Sim Zacks
Date:
Subject: Re: Change view with dependencies function: PG 8.3
Next
From: Machiel Richards
Date:
Subject: Database integrity ?