distinct aggregate with complex type dont see the equality operator - Mailing list pgsql-sql

From Thomas Chille
Subject distinct aggregate with complex type dont see the equality operator
Date
Msg-id cad2de1c0605291314y32e492e8gce5789eaf8a772cf@mail.gmail.com
Whole thread Raw
List pgsql-sql
Dear List,

i want to built an aggregate function wich should summing up values in
a distinct manner:

dsum(DISTINCT ROW(value, distinction)).

I implemented all things i thought i need but it dont work. i get
always an 'could not identify an equality operator for type
dsum_type'-error nevertheless the operator will be identified outside
the aggregate.

Here is the code for the equality operator:

CREATE OR REPLACE FUNCTION dsum_type_greater(dsum_type, dsum_type)
RETURNS boolean AS $f$   SELECT $1.distinction > $2.distinction;
$f$ LANGUAGE sql IMMUTABLE STRICT;

CREATE OPERATOR = (   PROCEDURE = dsum_type_equality,   LEFTARG = dsum_type,   RIGHTARG = dsum_type,   COMMUTATOR = =
);

And this happens:

-- result is FALSE
SELECT ROW(5, 'foo')::dsum_type = ROW(5, 'bar')::dsum_type;

-- result is TRUE
SELECT ROW(5, 'foo')::dsum_type = ROW(5, 'foo')::dsum_type;

-- result is TRUE
SELECT ROW(4, 'foo')::dsum_type = ROW(5, 'foo')::dsum_type;

-- works for me
SELECT dsum(ROW(wert, name)::dsum_type) FROM table1;

-- ERROR: could not identify an equality operator for type dsum_type
SELECT dsum(DISTINCT ROW(wert, name)::dsum_type) FROM table1;

i added the less then and greater then ops too, but it still wont work.

What i am doing wrong or can i achieve the wished result without
usinge a comlex type?

regards,
Thomas!


pgsql-sql by date:

Previous
From: Mauro Bertoli
Date:
Subject: Get max value from an comma separated string
Next
From: "Thomas Chille"
Date:
Subject: Re: distinct aggregate with complex type dont see the equality operator [solved]