Re: Comparing arrays of composite types

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
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 19:23:21
Message-ID: b42b73150908211223q71cec434m959ab185bc1d1b14@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 21, 2009 at 2:59 PM, Alban
Hertroys<dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> wrote:
> Hello all,
>
> I'm running into a small problem (while comparing tokenised unit strings in
> case you're interested) with said topic.
>
> I defined a type:
> CREATE TYPE unit_token AS (
>        base_unit       TEXT,
>        unit_base       INT
> );
>
> In my table I have:
> CREATE TABLE unit (
>        unit    TEXT NOT NULL PRIMARY KEY,
>        tokens  unit_token[] NOT NULL
> );
>
> 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".
>
> I can compare columns of type unit_token (not the array) just fine, and even
> joining on tokens[1] works as expected - and not just for equality but also
> less-than (didn't test the remainder, I assume they work).
>
> 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.
>
> I noticed casting both sides to text works just fine, but I'd prefer to do
> this 'properly' if possible. Any pointers as to what is going wrong here?
>
> One other thing of note is that the error doesn't appear to be about a
> missing comparison operator for unit_token, but rather for unit_token[].

This works in 8.4. Can you upgrade?

postgres=# select array(select foo from foo) = array(select foo from foo) ;
?column?
----------
t
(1 row)

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2009-08-21 19:24:25 Re: join from array or cursor
Previous Message David Kerr 2009-08-21 19:22:43 Re: export a schema / import as new schema