Re: [personal] Re: Filtering duplicated row with a trigger

From: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
To: papapep <papapep(at)gmx(dot)net>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [personal] Re: Filtering duplicated row with a trigger
Date: 2003-10-06 17:18:37
Message-ID: 3F81A3ED.8000705@e-trolley.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

papapep wrote:
> If so, how should I do
> the duplicates control in the temp table? (for me is as difficult as my
> first question :-( )
> Consider that the primary key that we use to see if the row is
> duplicated, or not, is a 5 fields key (it has to be so, is a complex
> data to filter).

CREATE TEMP TABLE tempo (a int, b int, c text);
INSERT INTO tempo (a,b,c) values (1,1,'foo');
INSERT INTO tempo (a,b,c) values (1,2,'bar');
INSERT INTO tempo (a,b,c) values (1,1,'foo');
INSERT INTO tempo (a,b,c) values (1,1,'foo');
INSERT INTO tempo (a,b,c) values (1,1,'foo-bar');

SELECT distinct on (a,b) a, b, c from tempo;
a | b | c
---+---+-----
1 | 1 | foo
1 | 2 | bar
(2 Zeilen)

This DISTINCT ON select only cares for the given arguments (a,b) to be
distinct. Which c is returned is undefined (random).

HTH
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message papapep 2003-10-06 17:28:29 Re: [personal] Re: Filtering duplicated row with a trigger
Previous Message Josh Berkus 2003-10-06 17:13:57 Re: [personal] Re: Filtering duplicated row with a trigger