Skip to content

Commit 124772e

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 2f29fd4 commit 124772e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

doc/src/sgml/func.sgml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15387,7 +15387,12 @@ table2-mapping
1538715387
calls.
1538815388
</para>
1538915389
<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>
1539115396
<returnvalue></returnvalue>
1539215397
<programlisting>
1539315398
a | b | c
@@ -15419,7 +15424,10 @@ table2-mapping
1541915424
for <function>json[b]_populate_record</function>.
1542015425
</para>
1542115426
<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>
1542315431
<returnvalue></returnvalue>
1542415432
<programlisting>
1542515433
a | b
@@ -15456,7 +15464,10 @@ table2-mapping
1545615464
input record value, unmatched columns are always filled with nulls.
1545715465
</para>
1545815466
<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>
1546015471
<returnvalue></returnvalue>
1546115472
<programlisting>
1546215473
a | b | c | d | r

0 commit comments

Comments
 (0)