Re: Adding PRIMARY KEY: Table contains duplicated values

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding PRIMARY KEY: Table contains duplicated values
Date: 2013-02-04 14:57:53
Message-ID: CAADeyWiT=wqJcFfT-Sm1n5Z4LQv4fhK77bdRs0N3CaQDqfk8MQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Unfortunately that fails -

On Mon, Feb 4, 2013 at 3:55 PM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> wrote:
> On 02/04/2013 06:45 AM, Alexander Farber wrote:
>>
>> Trying to delete the older of the duplicated pairs:
>>
>
> 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

# SELECT id, author, count(1), max(stamp) as maxx
pref-> FROM pref_rep
pref-> GROUP BY id, author
pref-> HAVING count(1) >1 and stamp < max(stamp);
ERROR: column "pref_rep.stamp" must appear in the GROUP BY clause or
be used in an aggregate function
LINE 4: HAVING count(1) >1 and stamp < max(stamp);

In response to

Browse pgsql-general by date

  From Date Subject
Next Message zeljko 2013-02-04 15:03:53 Re: Diferences between IN and EXISTS?
Previous Message Adrian Klaver 2013-02-04 14:55:21 Re: Adding PRIMARY KEY: Table contains duplicated values