The attached tiny patch lets the to_json(b) routines convert objects
with array pseudotypes to json{b}. The main impetus for this came from
my trying to convert the annyarray columns in pg_stats to json and
finding that they ended up as text instead of json arrays. This way
to_json on these columns does what is expected.
Advertising
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 628e9de..0ed6a10 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -1397,9 +1397,10 @@ json_categorize_type(Oid typoid,
default:
/* Check for arrays and composites */
- if (OidIsValid(get_element_type(typoid)))
+ if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
+ || typoid == RECORDARRAYOID)
*tcategory = JSONTYPE_ARRAY;
- else if (type_is_rowtype(typoid))
+ else if (type_is_rowtype(typoid)) /* includes RECORDOID */
*tcategory = JSONTYPE_COMPOSITE;
else
{
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index b9bf18f..5b6178b 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -644,9 +644,10 @@ jsonb_categorize_type(Oid typoid,
default:
/* Check for arrays and composites */
- if (OidIsValid(get_element_type(typoid)))
+ if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
+ || typoid == RECORDARRAYOID)
*tcategory = JSONBTYPE_ARRAY;
- else if (type_is_rowtype(typoid))
+ else if (type_is_rowtype(typoid)) /* includes RECORDOID */
*tcategory = JSONBTYPE_COMPOSITE;
else
{
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers