Re: (un)grouping question

From: Andrei Kovalevski <andyk(at)commandprompt(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Rhys Stewart <rhys(dot)stewart(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: (un)grouping question
Date: 2008-01-21 20:05:41
Message-ID: 4794FB15.6050904@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Davis wrote:
> On Mon, 2008-01-21 at 14:25 -0500, Rhys Stewart wrote:
>
>> ok, let me clarify, dont want to remove them just want them changed
>> but need to keep the uid. However, I would like just one somevalue to
>> remain the same. so for example, uids, 2,4 and 8 have somevalue 44,
>> after i would like 2 to remain 44 but uids 4 and 8 would be changed.
>>
>
> Can you explain why you're trying to do this? It's a very unusual
> requirement.
>
> That being said, the query would look something like this:
>
> (SELECT MIN(uid) AS uid, somevalue FROM mytable GROUP BY somevalue)
> UNION
> (SELECT uid, somevalue + random() AS somevalue
> FROM mytable WHERE uid NOT IN
> (SELECT MIN(uid)
> FROM mytable GROUP by somevalue)
>
> Disclaimer: I haven't actually tested this query, but it looks about
> right.
>

How can you garantee that "somevalue + random()" won't duplicate other
unique values in this column? ;)

> Regards,
> Jeff Davis
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Afakeo Nameo 2008-01-21 20:21:38 US Military / Government Approval
Previous Message Christian Schröder 2008-01-21 20:01:09 Re: Views and permissions