File: jsonb.out

package info (click to toggle)
pljs 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,704 kB
  • sloc: ansic: 69,356; javascript: 5,408; sql: 878; makefile: 443; sh: 123
file content (25 lines) | stat: -rw-r--r-- 527 bytes parent folder | download
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
CREATE FUNCTION get_key(key text, json_data jsonb) RETURNS jsonb
LANGUAGE pljs IMMUTABLE STRICT
AS $$
  var val = json_data[key];
  var ret = {};
  ret[key] = val;
  return JSON.stringify(ret);
$$;
CREATE TABLE jsonbonly (
    data jsonb
);
COPY jsonbonly (data) FROM stdin;
-- Call twice to test the function cache.
SELECT get_key('ok', data) FROM jsonbonly;
     get_key     
-----------------
 "{\"ok\":true}"
(1 row)

SELECT get_key('ok', data) FROM jsonbonly;
     get_key     
-----------------
 "{\"ok\":true}"
(1 row)