Los operadores de comparación (=, <, etc.) requieren que los argumentos izquierdo y derecho sean del mismo tipo. Exceptuando la igualdad y la no igualdad, los otros operadores de comparación no son útiles en el mundo real, pero permiten construir índices de árbol B en tipos de rango o de tiempo. Para los valores de rango, los operadores comparan primero el límite inferior y luego el límite superior. Para los valores de conjunto de marcas de tiempo y conjunto de períodos, los operadores comparan primero los períodos delimitadores y, si son iguales, comparan los primeros N instantes o períodos, donde N es el mínimo del número de instantes o períodos que componen ambos valores.
Los operadores de comparación disponibles para los tipos de conjunto y de rango se dan a continuación. Recuerde que los rangos de enteros siempre se representan por su forma canónica.
Comparaciones tradicionales
set {=, <>, <, >, <=, >=} set → boolean
spans {=, <>, <, >, <=, >=} spans → boolean
cmp({set,span,spanset},{set,span,spanset}) → int
SELECT intspan '[1,3]' = intspan '[1,4)';
-- true
SELECT floatspanset '{[1, 2),[2,3)}' = floatspanset '{[1,3)}';
-- true
SELECT tstzset '{2001-01-01, 2001-01-04}' <> tstzset '{2001-01-01, 2001-01-05}';
-- false
SELECT tstzspan '[2001-01-01, 2001-01-04)' <> tstzspan '[2001-01-03, 2001-01-05)';
-- true
SELECT floatspan '[3, 4]' < floatspan '(3, 4]';
-- true
SELECT intspanset '{[1,2],[3,4]}' < intspanset '{[3, 4]}';
-- true
SELECT floatspan '[3, 4]' > floatspan '[3, 4)';
-- true
SELECT tstzspan '[2001-01-03, 2001-01-04)' > tstzspan '[2001-01-02, 2001-01-05)';
-- true
SELECT floatspanset '{[1, 4)}' <= floatspanset '{[1, 5), [6, 7)}';
-- true
SELECT tstzspanset '{[2001-01-01, 2001-01-04)}' <= tstzspanset '{[2001-01-01,
2001-01-05), [2001-01-06, 2001-01-07)}';
-- true
SELECT tstzspan '[2001-01-03, 2001-01-05)' >= tstzspan '[2001-01-03, 2001-01-04)';
-- true
SELECT intspanset '{[1, 4)}' >= intspanset '{[1, 5), [6, 7)}';
-- false
SELECT cmp(intspanset '{[1, 4)}', intspanset '{[1, 5), [6, 7)}');
-- -1
Valores hash
hash({set,span,spanset}) → int
hashExtended({set,span,spanset},seed bigint) → bigint
La función hash devuelve un valor hash de 32 bits y la función hashExtended un valor hash de 64 bits calculado con la semilla dada. Los valores iguales tienen valores hash iguales, que es en lo que se basan los índices hash, las uniones hash y la agregación hash.
SELECT hash(intspan '[1,3]') = hash(intspan '[1,4)');
-- true
SELECT hash(intspanset '{[1,2],[3,4]}') = hash(intspanset '{[1,3),[3,5)}');
-- true
SELECT hash(tstzset '{2001-01-01, 2001-01-04}') =
hash(tstzset '{2001-01-04, 2001-01-01}');
-- true
SELECT hashExtended(tstzspan '[2001-01-01, 2001-01-04)', 0) <>
hashExtended(tstzspan '[2001-01-01, 2001-01-04)', 1);
-- true