]> git.8kb.co.uk Git - postgresql/pg_jsonb_opx/blob - jsonb_opx_sql_comparison.sql
Raise an error if un implemented append function called.
[postgresql/pg_jsonb_opx] / jsonb_opx_sql_comparison.sql
1 -- The functions in this script are SQL versions of the C ones for comparison
2 -- of performance between the two.
3
4 CREATE OR REPLACE FUNCTION jsonb_delete_left(a jsonb, b text)
5 RETURNS jsonb AS
6 $BODY$
7 SELECT COALESCE(
8 (
9 SELECT ('{' || string_agg(to_json(key) || ':' || value, ',') || '}')
10 FROM jsonb_each(a)
11 WHERE key <> b
12 )
13 , '{}')::jsonb;
14 $BODY$
15 LANGUAGE sql IMMUTABLE STRICT;
16
17 --
18
19 CREATE OR REPLACE FUNCTION jsonb_delete_left(a jsonb, b text[])
20 RETURNS jsonb AS
21 $BODY$
22 SELECT COALESCE(
23 (
24 SELECT ('{' || string_agg(to_json(key) || ':' || value, ',') || '}')
25 FROM jsonb_each(a)
26 WHERE key <> ALL(b)
27 )
28 , '{}')::jsonb;
29 $BODY$
30 LANGUAGE sql IMMUTABLE STRICT;
31
32 --
33
34 CREATE OR REPLACE FUNCTION jsonb_delete_left(a jsonb, b jsonb)
35 RETURNS jsonb AS
36 $BODY$
37 SELECT COALESCE(
38 (
39 SELECT ('{' || string_agg(to_json(key) || ':' || value, ',') || '}')
40 FROM jsonb_each(a)
41 WHERE NOT ('{' || to_json(key) || ':' || value || '}')::jsonb <@ b
42 )
43 , '{}')::jsonb;
44 $BODY$
45 LANGUAGE sql IMMUTABLE STRICT;
46
47 --
48
49 CREATE OR REPLACE FUNCTION jsonb_concat_left (a jsonb, b jsonb) 
50 RETURNS jsonb AS
51 $BODY$
52 SELECT json_object_agg(key, value)::jsonb FROM
53 (
54   SELECT * FROM jsonb_each(a)
55   UNION ALL
56   SELECT * FROM jsonb_each(b)
57 ) a;
58 $BODY$
59 LANGUAGE sql IMMUTABLE STRICT;