diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-08-13 20:00:38 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-08-13 20:00:38 -0400 |
commit | a9306f10b95992ec7229cae3de507a9fa2f6aa3c (patch) | |
tree | a13a4d7d567601e07cb7f54c59bd9ed5325e9dcf | |
parent | 1f51c17c68d05c28d5b9294d8013cb9e7e653160 (diff) | |
download | postgresql-a9306f10b95992ec7229cae3de507a9fa2f6aa3c.tar.gz postgresql-a9306f10b95992ec7229cae3de507a9fa2f6aa3c.zip |
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.
-rw-r--r-- | doc/src/sgml/func.sgml | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index f766c1bc67c..9a4ac5a1ea3 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -15414,7 +15414,12 @@ table2-mapping calls. </para> <para> - <literal>select * from json_populate_record(null::myrowtype, '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}}')</literal> + <literal>create type subrowtype as (d int, e text);</literal> + <literal>create type myrowtype as (a int, b text[], c subrowtype);</literal> + </para> + <para> + <literal>select * from json_populate_record(null::myrowtype, + '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}')</literal> <returnvalue></returnvalue> <programlisting> a | b | c @@ -15446,7 +15451,10 @@ table2-mapping for <function>json[b]_populate_record</function>. </para> <para> - <literal>select * from json_populate_recordset(null::myrowtype, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal> + <literal>create type twoints as (a int, b int);</literal> + </para> + <para> + <literal>select * from json_populate_recordset(null::twoints, '[{"a":1,"b":2},{"a":3,"b":4}]')</literal> <returnvalue></returnvalue> <programlisting> a | b @@ -15483,7 +15491,10 @@ table2-mapping input record value, unmatched columns are always filled with nulls. </para> <para> - <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> + <literal>create type myrowtype as (a int, b text);</literal> + </para> + <para> + <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> <returnvalue></returnvalue> <programlisting> a | b | c | d | r |