Re: [personal] Re: Filtering duplicated row with a trigger - Mailing list pgsql-novice

From Nabil Sayegh
Subject Re: [personal] Re: Filtering duplicated row with a trigger
Date
Msg-id 3F81A3ED.8000705@e-trolley.de
Whole thread Raw
In response to Re: [personal] Re: Filtering duplicated row with a trigger  (papapep <papapep@gmx.net>)
List 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


pgsql-novice by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [personal] Re: Filtering duplicated row with a trigger
Next
From: Bruno Wolff III
Date:
Subject: Re: [personal] Re: Filtering duplicated row with a trigger