sql >> Base de Datos >  >> RDS >> PostgreSQL

funciones de matriz biginteger


Puede sustituir su propia función. Este es razonablemente rápido:

CREATE OR REPLACE FUNCTION arr_subtract(int8[], int8[])
  RETURNS int8[] AS
$func$
SELECT ARRAY(
    SELECT a
    FROM   unnest($1) WITH ORDINALITY x(a, ord)
    WHERE  a <> ALL ($2)
    ORDER  BY ord
    );
$func$  LANGUAGE sql IMMUTABLE;

Llamar:

SELECT arr_subtract('{3,5,6,7,8,9}':: int8[], '{3,4,8}'::int8[]);

Resultado:

{5,6,7,9}

Mantiene el orden original de la matriz.

Relacionado:

  • PostgreSQL unnest() con número de elemento
  • Excluir elementos de matriz coincidentes