Doc: improve examples for json_populate_record() and related functions.
authorTom Lane
Fri, 14 Aug 2020 00:00:39 +0000 (20:00 -0400)
committerTom Lane
Fri, 14 Aug 2020 00:00:39 +0000 (20:00 -0400)
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.

doc/src/sgml/func.sgml

index 7275bf51d38b3a153844981c477c69499418232c..b1c92196e266aeb63e252b9e9e3a0d578cbb7873 100644 (file)
@@ -15387,7 +15387,12 @@ table2-mapping
         calls.
        
        
-        select * from json_populate_record(null::myrowtype, '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a  b c"}}')
+        create type subrowtype as (d int, e text);
+        create type myrowtype as (a int, b text[], c subrowtype);
+       
+       
+        select * from json_populate_record(null::myrowtype,
+         '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a  b c"}, "x": "foo"}')
         
 
  a |   b       |      c
@@ -15419,7 +15424,10 @@ table2-mapping
         for json[b]_populate_record.
        
        
-        select * from json_populate_recordset(null::myrowtype, '[{"a":1,"b":2},{"a":3,"b":4}]')
+        create type twoints as (a int, b int);
+       
+       
+        select * from json_populate_recordset(null::twoints, '[{"a":1,"b":2},{"a":3,"b":4}]')
         
 
  a | b
@@ -15456,7 +15464,10 @@ table2-mapping
         input record value, unmatched columns are always filled with nulls.
        
        
-        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) 
+        create type myrowtype as (a int, b text);
+       
+       
+        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)
         
 
  a |    b    |    c    | d |       r