Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a9306f1

Browse files
committed
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.
1 parent 1f51c17 commit a9306f1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

doc/src/sgml/func.sgml

+14-3
Original file line numberDiff line numberDiff line change
@@ -15414,7 +15414,12 @@ table2-mapping
1541415414
calls.
1541515415
</para>
1541615416
<para>
15417-
<literal>select * from json_populate_record(null::myrowtype, '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}}')</literal>
15417+
<literal>create type subrowtype as (d int, e text);</literal>
15418+
<literal>create type myrowtype as (a int, b text[], c subrowtype);</literal>
15419+
</para>
15420+
<para>
15421+
<literal>select * from json_populate_record(null::myrowtype,
15422+
'{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}')</literal>
1541815423
<returnvalue></returnvalue>
1541915424
<programlisting>
1542015425
a | b | c
@@ -15446,7 +15451,10 @@ table2-mapping
1544615451
for <function>json[b]_populate_record</function>.
1544715452
</para>
1544815453
<para>
15449-
<literal>select * from json_populate_recordset(null::myrowtype, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal>
15454+
<literal>create type twoints as (a int, b int);</literal>
15455+
</para>
15456+
<para>
15457+
<literal>select * from json_populate_recordset(null::twoints, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal>
1545015458
<returnvalue></returnvalue>
1545115459
<programlisting>
1545215460
a | b
@@ -15483,7 +15491,10 @@ table2-mapping
1548315491
input record value, unmatched columns are always filled with nulls.
1548415492
</para>
1548515493
<para>
15486-
<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>
15494+
<literal>create type myrowtype as (a int, b text);</literal>
15495+
</para>
15496+
<para>
15497+
<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>
1548715498
<returnvalue></returnvalue>
1548815499
<programlisting>
1548915500
a | b | c | d | r

0 commit comments

Comments
 (0)