Skip site navigation (1) Skip section navigation (2)

Re: Generic hash function?

From: Brian Hurt <bhurt(at)janestcapital(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Generic hash function?
Date: 2006-12-03 21:47:40
Message-ID: 457345FC.7020507@janestcapital.com (view raw or flat)
Thread:
Lists: pgsql-novice
Tom Lane wrote:

>Brian Hurt <bhurt(at)janestcapital(dot)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

In response to

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2006-12-03 22:15:10
Subject: Re: Generic hash function?
Previous:From: Tom LaneDate: 2006-12-03 21:33:20
Subject: Re: Generic hash function?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group