summaryrefslogtreecommitdiff
path: root/sql/json_set.sql
blob: 71c7a4cbbe3bff858ab48bfdf43d376464f5251a (plain)
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
28
29
30
31
SELECT json_set('[1,2,3]', '[1]', 5::json);
SELECT json_set('[1,2,3]', '[3]', 5::json);
SELECT json_set('[1,2,3]', '[2]', 5::json);
SELECT json_set('[1,2,3]', '[2]', '[0,1]'::json);
SELECT json_set('  [ 1 ,   2,3]', '1', '5');
SELECT json_set('  [ 1 ,   [2,3],3]', '1', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[1][0]', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[5][0]', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[4][0]', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[3][0]', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[2][0]', '5');
SELECT json_set('  [ 1 ,   [  2 ,   3     ],3]', '[1][0]', '   5  ');
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1][0]', '   5  ');
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1 ][0]', '   5  ');
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1 ][0]', '     5  ');
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1 ][0]', $$     "hello\tworld"  $$);
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1 ][0]', $$     "hello\u0009world"  $$);
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '[1 ][*]', $$     "hello\u0009world"  $$);
SELECT json_set('  [ 1 ,   [  2 ,   3     ]  , 3  ] ', '$', $$     "hello\u0009world"  $$);
SELECT json_set('       [ 1 ,   [  2 ,   3     ]  , 3  ] ', '$', $$     "hello\u0009world"  $$);

-- Since JavaScript doesn't do anything when you assign to a character subscript,
-- neither will json_set.
SELECT json_set('"hello"', '[0]', '"H"');
SELECT json_set('"hello"', '[0][0]', '"H"');
SELECT json_set('["hello"]', '[0][0]', '"H"');
SELECT json_set('["hello"]', '[0][0][0]', '"H"');

SELECT json_set('[0,1,2,[3,4,5],4]', '$[*]', '["set"]');
SELECT json_set('[0,1,2,[3,4,5],4]', '$[*][*]', '["set"]');
SELECT json_set('[0,1,2,[3,4,5],4]', '$..[*]', '["set"]');