Re: Comparing arrays of composite types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
Cc: postgres list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Comparing arrays of composite types
Date: 2009-08-21 20:12:40
Message-ID: 9512.1250885560@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> writes:
> I defined a type:
> CREATE TYPE unit_token AS (
> base_unit TEXT,
> unit_base INT
> );

> If I try to join on tokens or try to create an index over that column
> I get: "ERROR: could not identify a comparison function for type
> unit_token".

As noted, there is a built-in solution as of 8.4.

> I have created operators on unit_token for =, <, <=, > and >=, but
> either I did something wrong defining my operators or the error is
> pointing to some other problem.

The mere fact that the operator is named '=' means nothing to Postgres.
You need to create an operator class or family that shows the operator
is equality in a btree opclass. Array comparison looks for the default
btree opclass for the element data type to decide what to do.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nathan Jahnke 2009-08-21 21:26:49 bytea corruption?
Previous Message David Kerr 2009-08-21 20:00:40 Re: Schema diff tool?