Re: Generic hash function? - Mailing list pgsql-novice

From Brian Hurt
Subject Re: Generic hash function?
Date
Msg-id 457345FC.7020507@janestcapital.com
Whole thread Raw
In response to Re: Generic hash function?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Generic hash function?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Tom Lane wrote:
Brian Hurt <bhurt@janestcapital.com> writes: 
I'm trying to write a generic equals operator that works on type 
anyelement,   
What for?  You'd ultimately have to depend on the various actual input
types' native equality operators, so I don't see what this'd buy except
a layer of useless-seeming overhead.  Also, it could only be hashable
if the input type's equality is hashable, and we don't have any way to
deal with a "sometimes hashable" equality operator.
		regards, tom lane

 

What I'd like to write is:

CREATE FUNCTION eqnull(anyelement, anyelement) RETURNS BOOLEAN AS $_$
        SELECT
          (CASE
            WHEN $1 IS NULL AND $2 IS NULL THEN TRUE
            WHEN ($1 IS NULL AND $2 IS NOT NULL)
              OR ($1 IS NOT NULL AND $2 IS NULL)
              THEN FALSE
            ELSE $1 = $2
            END
          )
$_$ IMMUTABLE LANGUAGE SQL;

Which changes how nulls are handled.  This makes writing certain kinds of queries much easier and much more clear what the query is doing.

Am I going to need to create an operator class for every type?

Brian

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Generic hash function?
Next
From: Tom Lane
Date:
Subject: Re: Generic hash function?