云数据库 GaussDB-集合支持的函数:集合MULTISET函数

时间:2023-11-01 16:18:34

集合MULTISET函数

  • MULTISET UNION [ALL | DISTINCT]

    参数:nesttable类型

    返回值:nesttable类型

    功能描述:两个集合变量的并集,ALL不去除重复元素,DISTINCT去除重复元素。

    示例:

    gaussdb=# declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2);gaussdb-#     b nest := nest(2,3);gaussdb-# begingaussdb$#     a := a MULTISET UNION ALL b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {1,2,2,3}ANONYMOUS BLOCK EXECUTE gaussdb=# declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2);gaussdb-#     b nest := nest(2,3);gaussdb-# begingaussdb$#     a := a MULTISET UNION DISTINCT b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {1,2,3}ANONYMOUS BLOCK EXECUTE
  • MULTISET EXCEPT [ALL | DISTINCT]

    参数:nesttable类型

    返回值:nesttable类型

    功能描述:两个集合变量的差集。如A MULTISET EXCEPT B:ALL表示去除A中与B重复的元素;DISTINCT表示先对A进行去重操作,然后去除与B中有重复的元素。

    示例:

    gaussdb=# declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2,2);gaussdbs-#     b nest := nest(2,3);gaussdb-# begingaussdb$#     a := a MULTISET EXCEPT ALL b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {1,2}ANONYMOUS BLOCK EXECUTE gaussdb=# declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2,2);gaussdb-#     b nest := nest(2,3);gaussdb-# begingaussdb$#     a := a MULTISET EXCEPT DISTINCT b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {1}ANONYMOUS BLOCK EXECUTE
  • MULTISET INTERSECT [ALL | DISTINCT]

    参数:nesttable类型

    返回值:nesttable类型

    功能描述:两个集合变量的交集。如 A MULTISET INTERSECT B:ALL表是取A与B所有重复的元素;DISTINCT表示取A与B中重复元素,且去除重复元素。

    示例:

    gaussdb=#  declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2,2);gaussdbs-#     b nest := nest(2,2,3);gaussdb-# begingaussdb$#     a := a MULTISET INTERSECT ALL b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {2,2}ANONYMOUS BLOCK EXECUTE gaussdb=# declaregaussdb-#     type nest is table of int;gaussdb-#     a nest := nest(1,2,2);gaussdb-#     b nest := nest(2,2,3);gaussdb-# begingaussdb$#     a := a MULTISET INTERSECT DISTINCT b;gaussdb$#     raise info '%', a;gaussdb$# end;gaussdb$# /INFO:  {2}ANONYMOUS BLOCK EXECUTE
support.huaweicloud.com/centralized-devg-v3-opengauss/gaussdb-12-0730.html