@@ -34,6 +34,48 @@ This function accepts a :eql:type:`str` as an argument and produces a
3434
3535 .. _ref_datamodel_functions_modifying :
3636
37+ Sets as arguments
38+ ^^^^^^^^^^^^^^^^^
39+
40+ Calling a user-defined function on a set will always apply it as
41+ :ref: `*element-wise* <_ref_reference_cardinality_functions_operators >`.
42+
43+ .. code-block :: sdl
44+
45+ function magnitude(x: float64) -> float64
46+ using (
47+ math::sqrt(sum(x * x))
48+ );
49+
50+ .. code-block :: edgeql-repl
51+
52+ db> select magnitude({3, 4});
53+ {3, 4}
54+
55+ In order to pass in multiple arguments at once, arguments should be packed into
56+ arrays:
57+
58+ .. code-block :: sdl
59+
60+ function magnitude(xs: array<float64>) -> float64
61+ using (
62+ with x := array_unpack(xs)
63+ select math::sqrt(sum(x * x))
64+ );
65+
66+ .. code-block :: edgeql-repl
67+
68+ db> select magnitude([3, 4]);
69+ {5}
70+
71+ Multiple packed arrays can be passed into such a function, which will then be
72+ applied element-wise.
73+
74+ .. code-block :: edgeql-repl
75+
76+ db> select magnitude({[3, 4], [5, 12]});
77+ {5, 13}
78+
3779 Modifying Functions
3880^^^^^^^^^^^^^^^^^^^
3981
@@ -93,6 +135,18 @@ then the following queries are valid:
93135 db> select add_user('May', <datetime>'2024-12-11T12:00:00-07:00') {name, joined_at};
94136 {default::User {name: 'May', joined_at: <datetime>'2024-12-11T12:00:00Z'}}
95137
138+ In order to insert or update a multi parameter, the desired arguments should be
139+ aggregated into an array as described above:
140+
141+ .. code-block :: sdl
142+
143+ function add_user(name: str, nicknames: array<str>) -> User
144+ using (
145+ insert User {
146+ name := name,
147+ nicknames := array_unpack(nicknames),
148+ }
149+ );
96150
97151 .. list-table ::
98152 :class: seealso
0 commit comments