<indexterm>
<primary>json_to_record</primary>
</indexterm>
+ <indexterm>
+ <primary>jsonb_to_record</primary>
+ </indexterm>
<indexterm>
<primary>json_to_recordset</primary>
</indexterm>
+ <indexterm>
+ <primary>jsonb_to_recordset</primary>
+ </indexterm>
<table id="functions-json-processing-table">
<title>JSON Processing Functions</title>
<entry><literal>number</literal></entry>
</row>
<row>
- <entry>
- <literal>json_to_record(json, nested_as_text bool)</literal>
- </entry>
+ <entry><para><literal>json_to_record(json [, nested_as_text bool=false])</literal>
+ </para><para><literal>jsonb_to_record(jsonb [, nested_as_text bool=false])</literal>
+ </para></entry>
<entry><type>record</type></entry>
<entry>
Returns an arbitrary record from a JSON object. As with all functions
</entry>
</row>
<row>
- <entry>
- <literal>json_to_recordset(json, nested_as_text bool)</literal>
- </entry>
+ <entry><para><literal>json_to_recordset(json [, nested_as_text bool=false])</literal>
+ </para><para><literal>jsonb_to_recordset(jsonb [, nested_as_text bool=false])</literal>
+ </para></entry>
<entry><type>setof record</type></entry>
<entry>
Returns an arbitrary set of records from a JSON object. As with
jsonb_populate_recordset(base anyelement, from_json jsonb, use_json_as_text boolean DEFAULT false)
RETURNS SETOF anyelement LANGUAGE internal STABLE ROWS 100 AS 'jsonb_populate_recordset';
+CREATE OR REPLACE FUNCTION
+ json_to_record(from_json json, nested_as_text boolean DEFAULT false)
+ RETURNS record LANGUAGE internal STABLE AS 'json_to_record';
+
+CREATE OR REPLACE FUNCTION
+ json_to_recordset(from_json json, nested_as_text boolean DEFAULT false)
+ RETURNS SETOF record LANGUAGE internal STABLE ROWS 100 AS 'json_to_recordset';
+
+CREATE OR REPLACE FUNCTION
+ jsonb_to_record(from_json jsonb, nested_as_text boolean DEFAULT false)
+ RETURNS record LANGUAGE internal STABLE AS 'jsonb_to_record';
+
+CREATE OR REPLACE FUNCTION
+ jsonb_to_recordset(from_json jsonb, nested_as_text boolean DEFAULT false)
+ RETURNS SETOF record LANGUAGE internal STABLE ROWS 100 AS 'jsonb_to_recordset';
+
CREATE OR REPLACE FUNCTION pg_logical_slot_get_changes(
IN slotname name, IN upto_lsn pg_lsn, IN upto_nchanges int, VARIADIC options text[] DEFAULT '{}',
OUT location pg_lsn, OUT xid xid, OUT data text)
return populate_record_worker(fcinfo, true);
}
+Datum
+jsonb_to_record(PG_FUNCTION_ARGS)
+{
+ return populate_record_worker(fcinfo, false);
+}
+
Datum
json_populate_record(PG_FUNCTION_ARGS)
{
return populate_recordset_worker(fcinfo, true);
}
+Datum
+jsonb_to_recordset(PG_FUNCTION_ARGS)
+{
+ return populate_recordset_worker(fcinfo, false);
+}
+
+Datum
+json_populate_recordset(PG_FUNCTION_ARGS)
+{
+ return populate_recordset_worker(fcinfo, true);
+}
+
+Datum
+json_to_recordset(PG_FUNCTION_ARGS)
+{
+ return populate_recordset_worker(fcinfo, false);
+}
+
static void
make_row_from_rec_and_jsonb(Jsonb * element, PopulateRecordsetState *state)
{
tuplestore_puttuple(state->tuple_store, rettuple);
}
-Datum
-json_populate_recordset(PG_FUNCTION_ARGS)
-{
- return populate_recordset_worker(fcinfo, true);
-}
-
-Datum
-json_to_recordset(PG_FUNCTION_ARGS)
-{
- return populate_recordset_worker(fcinfo, false);
-}
-
/*
* common worker for json_populate_recordset() and json_to_recordset()
*/
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201403121
+#define CATALOG_VERSION_NO 201403261
#endif
DESCR("get record fields from a jsonb object");
DATA(insert OID = 3475 ( jsonb_populate_recordset PGNSP PGUID 12 1 100 0 0 f f f f f t s 3 0 2283 "2283 3802 16" _null_ _null_ _null_ _null_ jsonb_populate_recordset _null_ _null_ _null_ ));
DESCR("get set of records with fields from a jsonb array of objects");
+DATA(insert OID = 3490 ( jsonb_to_record PGNSP PGUID 12 1 0 0 0 f f f f f f s 2 0 2249 "3802 16" _null_ _null_ _null_ _null_ jsonb_to_record _null_ _null_ _null_ ));
+DESCR("get record fields from a json object");
+DATA(insert OID = 3491 ( jsonb_to_recordset PGNSP PGUID 12 1 100 0 0 f f f f f t s 2 0 2249 "3802 16" _null_ _null_ _null_ _null_ jsonb_to_recordset _null_ _null_ _null_ ));
+DESCR("get set of records with fields from a json array of objects");
DATA(insert OID = 3210 ( jsonb_typeof PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3802" _null_ _null_ _null_ _null_ jsonb_typeof _null_ _null_ _null_ ));
DESCR("get the type of a jsonb value");
DATA(insert OID = 4038 ( jsonb_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3802 3802" _null_ _null_ _null_ _null_ jsonb_ne _null_ _null_ _null_ ));
extern Datum jsonb_array_elements(PG_FUNCTION_ARGS);
extern Datum jsonb_populate_record(PG_FUNCTION_ARGS);
extern Datum jsonb_populate_recordset(PG_FUNCTION_ARGS);
+extern Datum jsonb_to_record(PG_FUNCTION_ARGS);
+extern Datum jsonb_to_recordset(PG_FUNCTION_ARGS);
#endif /* JSON_H */
null \u0000 escape
(1 row)
+-- jsonb_to_record and jsonb_to_recordset
+select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}',true)
+ as x(a int, b text, d text);
+ a | b | d
+---+-----+---
+ 1 | foo |
+(1 row)
+
+select * from jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]',false)
+ as x(a int, b text, c boolean);
+ a | b | c
+---+-----+---
+ 1 | foo |
+ 2 | bar | t
+(2 rows)
+
-- indexing
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
count
null \u0000 escape
(1 row)
+-- jsonb_to_record and jsonb_to_recordset
+select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}',true)
+ as x(a int, b text, d text);
+ a | b | d
+---+-----+---
+ 1 | foo |
+(1 row)
+
+select * from jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]',false)
+ as x(a int, b text, c boolean);
+ a | b | c
+---+-----+---
+ 1 | foo |
+ 2 | bar | t
+(2 rows)
+
-- indexing
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
count
SELECT jsonb '{ "a": "dollar \u0024 character" }' ->> 'a' AS correct_everyWHERE;
SELECT jsonb '{ "a": "null \u0000 escape" }' ->> 'a' AS not_unescaped;
+-- jsonb_to_record and jsonb_to_recordset
+
+select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}',true)
+ as x(a int, b text, d text);
+
+select * from jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]',false)
+ as x(a int, b text, c boolean);
+
-- indexing
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":"CC"}';