example of json_to_record(json) not working

From: Sébastien DELOBEL <sdelobel(at)hotmail(dot)com>
To: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: example of json_to_record(json) not working
Date: 2018-09-03 14:34:51
Message-ID: DB6PR0601MB2040BA701A67B27E66F2C934D50C0@DB6PR0601MB2040.eurprd06.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

When you execute the example of the function "json_to_record(json)" in the documentation https://www.postgresql.org/docs/10/static/functions-json.html

PostgreSQL: Documentation: 10: 9.15. JSON Functions and ...<https://www.postgresql.org/docs/10/static/functions-json.html>
www.postgresql.org
Operator Right Operand Type Description Example Example Result-> int: Get JSON array element (indexed from zero, negative integers count from the end)

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)

the expected result is :

a | b | c | d | r
---+---------+---------+---+---------------
1 | [1,2,3] | {1,2,3} | | (123,"a b c")

But in my cluster PostgreSQL 9.5.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11), 64-bit

I have this result :

ERROR: type "myrowtype" does not exist
LINE 1: ...a b c"}}') as x(a int, b text, c int[], d text, r myrowtype)...
^

i think that query should be as follows to have the expected result:

select * from json_to_record('{"a":1,"b":[1,2,3],"c":"{4,5,6}","e":"bar","r": {"a": 123, "b": "a b c"}}') as x(a int, b text, c int[], d text, r json)

a | b | c | d | r
---+---------+---------+---+--------------------------
1 | [1,2,3] | {4,5,6} | | {"a": 123, "b": "a b c"}
(1 row)

Thanks you :)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-09-03 16:10:28 BUG #15362: llbeta3: ./configure; in x86_64-w64-mingw32-gcc 8.2.0 wrong options "-V" and "-qversion"
Previous Message Tom Lane 2018-09-03 13:49:17 Re: BUG #15324: Non-deterministic behaviour from parallelised sub-query