Commit 7c2c8ee
Add agtype <-> jsonb bidirectional casts (issue #350)
Register explicit casts between agtype and jsonb, enabling:
SELECT properties(n)::jsonb FROM cypher(...) AS (n agtype);
SELECT '{"key": "value"}'::jsonb::agtype;
-- Use jsonb operators on graph data:
SELECT (props::jsonb)->>'name' FROM cypher(...) AS (props agtype);
Implementation uses SQL language functions that go through proven
text-intermediate paths:
agtype -> jsonb: agtype_to_json() -> json::jsonb
jsonb -> agtype: jsonb::text -> text::agtype
This approach is safe because agtype extends jsonb's binary format
with types (AGTV_INTEGER, AGTV_FLOAT, AGTV_VERTEX, AGTV_EDGE,
AGTV_PATH) that jsonb does not recognize, making direct binary
conversion unreliable. The text roundtrip handles all value types
correctly including graph types (vertex/edge properties are
extracted as JSON objects).
All 31 regression tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 23146a4 commit 7c2c8ee
1 file changed
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
177 | 204 | | |
178 | 205 | | |
179 | 206 | | |
| |||
0 commit comments