Re: Adding PRIMARY KEY: Table contains duplicated values

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding PRIMARY KEY: Table contains duplicated values
Date: 2013-02-04 14:55:21
Message-ID: 510FCBD9.6080005@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/04/2013 06:45 AM, Alexander Farber wrote:
> Trying to delete the older of the duplicated pairs:
>
> # SELECT id, author, count(1), max(stamp) as maxx
> FROM pref_rep
> GROUP BY id, author
> HAVING count(1) >1 and stamp < maxx;
> ERROR: column "maxx" does not exist
> LINE 4: HAVING count(1) >1 and stamp < maxx;

How about:
SELECT id, author, count(1), max(stamp) as maxx
FROM pref_rep
GROUP BY id, author
HAVING count(1) >1 and stamp < max(stamp);

> ^
>
> On Mon, Feb 4, 2013 at 3:36 PM, Alexander Farber
> <alexander(dot)farber(at)gmail(dot)com> wrote:
>>>> http://stackoverflow.com/questions/14688523/adding-primary-key-table-contains-duplicated-values
>>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2013-02-04 14:57:53 Re: Adding PRIMARY KEY: Table contains duplicated values
Previous Message Misa Simic 2013-02-04 14:50:50 Re: partial time stamp query