try_member.sql 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* postgres can not */
  2. /* syntax version 1 */
  3. /* yt can not */
  4. $s = <|a:1, b:2u/1u, c:Just(Just(1))|>;
  5. $js = Just($s);
  6. $es = Nothing(Struct<a:Int32, b:Uint32?, c:Int32??>?);
  7. -- result of TryMember() when member is not present is third argument
  8. -- (optional third arg if struct is optional, but third arg is not)
  9. select
  10. TryMember($s, "z", 'qqq'),
  11. TryMember($js, "z", null),
  12. TryMember($es, "z", Just(Just('qqq'))),
  13. TryMember($js, "z", 'zzz'),
  14. ;
  15. -- fully equivalent to <struct>.<name>
  16. select
  17. TryMember($s, "a", null),
  18. TryMember($s, "b", null),
  19. TryMember($s, "c", null),
  20. TryMember($js, "a", null),
  21. TryMember($js, "b", null),
  22. TryMember($js, "c", null),
  23. TryMember($es, "a", null),
  24. TryMember($es, "b", null),
  25. TryMember($es, "c", null),
  26. ;
  27. -- TypeOf TryMember is type of third argument
  28. -- field type should either match third type exactly, or (if the third type is optional)
  29. -- Optional(field) should be equal to third type
  30. select
  31. TryMember($s, "a", 999),
  32. TryMember($s, "a", Just(999)),
  33. TryMember($s, "b", Just(999u)),
  34. TryMember($s, "c", Just(Just(999))),
  35. TryMember($js, "a", 999),
  36. TryMember($js, "a", Just(999)),
  37. TryMember($js, "b", Just(999u)),
  38. TryMember($js, "c", Just(Just(999))),
  39. TryMember($es, "a", 999),
  40. TryMember($es, "a", Just(999)),
  41. TryMember($es, "b", Just(999u)),
  42. TryMember($es, "c", Just(Just(999))),
  43. ;