Re: Generic hash function?
От | Brian Hurt |
---|---|
Тема | Re: Generic hash function? |
Дата | |
Msg-id | 457345FC.7020507@janestcapital.com обсуждение исходный текст |
Ответ на | Re: Generic hash function? (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Generic hash function?
|
Список | pgsql-novice |
Tom Lane wrote:
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
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 по дате отправления: