| From: | "Thomas Chille" <thomas(at)chille(dot)de> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | distinct aggregate with complex type dont see the equality operator |
| Date: | 2006-05-29 20:14:17 |
| Message-ID: | cad2de1c0605291314y32e492e8gce5789eaf8a772cf@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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!
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Penchalaiah P. | 2006-05-30 10:12:57 | hi i need to encrypt one field in a table |
| Previous Message | Mauro Bertoli | 2006-05-29 11:22:38 | Get max value from an comma separated string |