Re: Hashable custom types - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Hashable custom types
Date
Msg-id 13110.1436387502@sss.pgh.pa.us
Whole thread Raw
In response to Re: Hashable custom types  (Paul Ramsey <pramsey@cleverelephant.ca>)
Responses Re: Hashable custom types  (Paul Ramsey <pramsey@cleverelephant.ca>)
List pgsql-hackers
Paul Ramsey <pramsey@cleverelephant.ca> writes:
> On Fri, Apr 25, 2014 at 4:54 PM, Peter Geoghegan <pg@heroku.com> wrote:
>> On Fri, Apr 25, 2014 at 4:47 PM, Paul Ramsey <pramsey@cleverelephant.ca> wrote:
>>> Is it possible to make custom types hashable? There's no hook in the
>>> CREATE TYPE call for a hash function, but can one be hooked up
>>> somewhere else? In an operator?

>> See 35.14.6., System Dependencies on Operator Classes

> Coming back to this, I created an appropriate opclass...

> CREATE OR REPLACE FUNCTION geometry_hash_eq(geom1 geometry, geom2 geometry)
> RETURNS boolean
> AS '$libdir/postgis-2.2', 'lwgeom_hash_eq'
> LANGUAGE 'c' IMMUTABLE STRICT;

Why are you creating a separate equality operator, rather than just using
the type's existing equality operator (I assume it's got one) in the
hash opclass?

> It still says I lack the secret sauce...

> ERROR:  could not implement recursive UNION
> DETAIL:  All column datatypes must be hashable.

UNION will preferentially glom onto the btree equality operator, if memory
serves.  If that isn't also the hash equality operator, things won't work
pleasantly.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Paul Ramsey
Date:
Subject: Re: Hashable custom types
Next
From: Paul Ramsey
Date:
Subject: Re: Hashable custom types