You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doc: improve examples for json_populate_record() and related functions.
Make these examples self-contained by providing declarations of the
user-defined row types they rely on. There wasn't room to do this
in the old doc format, but now there is, and I think it makes the
examples a good bit less confusing.
Copy file name to clipboardExpand all lines: doc/src/sgml/func.sgml
+14-3Lines changed: 14 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -15387,7 +15387,12 @@ table2-mapping
15387
15387
calls.
15388
15388
</para>
15389
15389
<para>
15390
-
<literal>select * from json_populate_record(null::myrowtype, '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}}')</literal>
15390
+
<literal>create type subrowtype as (d int, e text);</literal>
15391
+
<literal>create type myrowtype as (a int, b text[], c subrowtype);</literal>
15392
+
</para>
15393
+
<para>
15394
+
<literal>select * from json_populate_record(null::myrowtype,
15395
+
'{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}')</literal>
15391
15396
<returnvalue></returnvalue>
15392
15397
<programlisting>
15393
15398
a | b | c
@@ -15419,7 +15424,10 @@ table2-mapping
15419
15424
for <function>json[b]_populate_record</function>.
15420
15425
</para>
15421
15426
<para>
15422
-
<literal>select * from json_populate_recordset(null::myrowtype, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal>
15427
+
<literal>create type twoints as (a int, b int);</literal>
15428
+
</para>
15429
+
<para>
15430
+
<literal>select * from json_populate_recordset(null::twoints, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal>
15423
15431
<returnvalue></returnvalue>
15424
15432
<programlisting>
15425
15433
a | b
@@ -15456,7 +15464,10 @@ table2-mapping
15456
15464
input record value, unmatched columns are always filled with nulls.
15457
15465
</para>
15458
15466
<para>
15459
-
<literal>select * from json_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') as x(a int, b text, c int[], d text, r myrowtype) </literal>
15467
+
<literal>create type myrowtype as (a int, b text);</literal>
15468
+
</para>
15469
+
<para>
15470
+
<literal>select * from json_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') as x(a int, b text, c int[], d text, r myrowtype)</literal>
0 commit comments