Re: no keys...

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Jeff Davis <list-pgsql-general(at)empires(dot)org>
Cc: Dorward Villaruz <dorwardv(at)ntsp(dot)nec(dot)co(dot)jp>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: no keys...
Date: 2002-07-16 20:48:29
Message-ID: Pine.LNX.4.44.0207161447480.30529-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 16 Jul 2002, Jeff Davis wrote:

> Each row automatically has an oid assigned to it, which can act as a key. It's
> sort of "hidden", but all you have to do is "select oid,* from mytable" to
> see it. Then you can delete based on that oid.
>
> Regards,
> Jeff
>
> On Tuesday 16 April 2002 12:31 pm, Dorward Villaruz wrote:
> > i have a table where there is no primary key
> >
> > i have 5 rows of data
> >
> > day1 time1
> > day1 time1
> > day1 time2
> > day1 time2
> > day1 time2
> >
> > time2 is newer than time1, how should i delete the four oldest record in
> > the table. this means that the only row that will be left on my table is:
> >
> > day1 time2

You can do something like this in sql:

delete from test where oid !=(select max(oid) from test group by time
order by time desc limit 1);

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2002-07-16 20:53:05 Re: table size growing out of control
Previous Message snpe 2002-07-16 20:43:56 Drop constraint