[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-sql
Subject:    [SQL] distinct aggregate with complex type dont see the equality operator
From:       "Thomas Chille" <thomas () chille ! de>
Date:       2006-05-29 20:14:17
Message-ID: cad2de1c0605291314y32e492e8gce5789eaf8a772cf () mail ! gmail ! com
[Download RAW message or body]

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!

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic