sets.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* postgres can not */
  2. $ns = ($set)->{return ListSort(DictKeys($set))};
  3. $nd = ($dict)->{return ListSort(DictItems($dict), ($z)->{return $z.0})};
  4. select $ns(ToSet(AsList(1,2,3)));
  5. select SetIsDisjoint(ToSet(AsList(1,2,3)), AsList(7,4));
  6. select SetIsDisjoint(ToSet(AsList(1,2,3)), AsList(3,4));
  7. select SetIsDisjoint(ToSet(AsList(1,2,3)), ToSet(AsList(7,4)));
  8. select SetIsDisjoint(ToSet(AsList(1,2,3)), ToSet(AsList(3,4)));
  9. select $ns(SetIntersection(ToSet(AsList(1,2,3)), ToSet(AsList(3,4))));
  10. select $nd(SetIntersection(
  11. AsDict(AsTuple(1,"foo"),AsTuple(3,"bar")),
  12. AsDict(AsTuple(1,"baz"),AsTuple(2,"qwe")),
  13. ($_k, $a, $b)->{ return AsTuple($a, $b) }));
  14. select SetIncludes(ToSet(AsList(1,2,3)), AsList(3,4));
  15. select SetIncludes(ToSet(AsList(1,2,3)), AsList(2,3));
  16. select SetIncludes(ToSet(AsList(1,2,3)), ToSet(AsList(3,4)));
  17. select SetIncludes(ToSet(AsList(1,2,3)), ToSet(AsList(2,3)));
  18. select $ns(SetDifference(ToSet(AsList(1,2,3)), ToSet(AsList(3,4))));
  19. select $ns(SetDifference(ToSet(AsList(1,2,3)), ToSet(AsList(2,3))));
  20. select $ns(SetUnion(ToSet(AsList(1,2,3)), ToSet(AsList(3,4))));
  21. select $nd(SetUnion(
  22. AsDict(AsTuple(1,"foo"),AsTuple(3,"bar")),
  23. AsDict(AsTuple(1,"baz"),AsTuple(2,"qwe")),
  24. ($_k, $a, $b)->{ return AsTuple($a, $b) }));
  25. select $ns(SetSymmetricDifference(ToSet(AsList(1,2,3)), ToSet(AsList(3,4))));
  26. select $nd(SetSymmetricDifference(
  27. AsDict(AsTuple(1,"foo"),AsTuple(3,"bar")),
  28. AsDict(AsTuple(1,"baz"),AsTuple(2,"qwe")),
  29. ($_k, $a, $b)->{ return AsTuple($a, $b) }));