Skip to content

Commit 600c82f

Browse files
committed
Merge remote-tracking branch 'origin/feature_agtype_jsonb_cast' into feature_agtype_jsonb_cast
2 parents cd0aebc + 3e1b2a1 commit 600c82f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

sql/agtype_coercions.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,33 @@ AS 'MODULE_PATHNAME';
174174
CREATE CAST (agtype AS json)
175175
WITH FUNCTION ag_catalog.agtype_to_json(agtype);
176176

177+
-- agtype -> jsonb (explicit)
178+
-- Uses text intermediate because agtype extends jsonb's binary format
179+
-- with types (AGTV_INTEGER, AGTV_FLOAT, AGTV_VERTEX, AGTV_EDGE, AGTV_PATH)
180+
-- that jsonb does not recognize.
181+
CREATE FUNCTION ag_catalog.agtype_to_jsonb(agtype)
182+
RETURNS jsonb
183+
LANGUAGE sql
184+
IMMUTABLE
185+
RETURNS NULL ON NULL INPUT
186+
PARALLEL SAFE
187+
AS 'SELECT ag_catalog.agtype_to_json($1)::jsonb';
188+
189+
CREATE CAST (agtype AS jsonb)
190+
WITH FUNCTION ag_catalog.agtype_to_jsonb(agtype);
191+
192+
-- jsonb -> agtype (explicit)
193+
CREATE FUNCTION ag_catalog.jsonb_to_agtype(jsonb)
194+
RETURNS agtype
195+
LANGUAGE sql
196+
IMMUTABLE
197+
RETURNS NULL ON NULL INPUT
198+
PARALLEL SAFE
199+
AS 'SELECT $1::text::agtype';
200+
201+
CREATE CAST (jsonb AS agtype)
202+
WITH FUNCTION ag_catalog.jsonb_to_agtype(jsonb);
203+
177204
CREATE FUNCTION ag_catalog.agtype_array_to_agtype(agtype[])
178205
RETURNS agtype
179206
LANGUAGE c

0 commit comments

Comments
 (0)