aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/expr/replace_member.sql
blob: 1e2e47ed7adb1ee2c508b7a2d60a282fa4ccca84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* postgres can not */
/* syntax version 1 */
$data = <|x: [<|y: 2|>], z: 5|>;

-- set field function
$F = ($field, $function) -> (
    ($struct) -> (
        ReplaceMember($struct, $field, $function($struct.$field))
    )
);

-- set list element function
$E = ($index, $function) -> (
    ($list) -> (
        ListMap(ListEnumerate($list), ($pair) -> (
            IF ($pair.0 = $index, $function($pair.1), $pair.1)
        ))
    )
);

-- set value function
$V = ($value) -> (
    ($_item) -> ($value)
);

SELECT $F("x", $E(0, $F("y", $V(3))))($data)