Skip to content

Commit da4cdc8

Browse files
authored
Merge pull request #2132 from dolthub/daylon/large-json
Fixed JSONB extended value error
2 parents df3db0a + 189f478 commit da4cdc8

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

server/functions/jsonb.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ var jsonb_out = framework.Function1{
6565
Parameters: [1]*pgtypes.DoltgresType{pgtypes.JsonB},
6666
Strict: true,
6767
Callable: func(ctx *sql.Context, _ [2]*pgtypes.DoltgresType, val any) (any, error) {
68+
res, err := sql.UnwrapAny(ctx, val)
69+
if err != nil {
70+
return nil, err
71+
}
6872
sb := strings.Builder{}
6973
sb.Grow(256)
70-
pgtypes.JsonValueFormatter(&sb, val.(pgtypes.JsonDocument).Value)
74+
pgtypes.JsonValueFormatter(&sb, res.(pgtypes.JsonDocument).Value)
7175
return sb.String(), nil
7276
},
7377
}

testing/go/types_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,21 @@ var typesTests = []ScriptTest{
14291429
},
14301430
},
14311431
},
1432+
{
1433+
Name: "JSONB large string",
1434+
SetUpScript: []string{
1435+
`CREATE TABLE t_jsonl (pk INT4 PRIMARY KEY, v1 JSONB);`,
1436+
`INSERT INTO t_jsonl VALUES (1, '{"key1": "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"}');`,
1437+
},
1438+
Assertions: []ScriptTestAssertion{
1439+
{
1440+
Query: "SELECT pk, length(v1::TEXT) FROM t_jsonl;",
1441+
Expected: []sql.Row{
1442+
{1, 4112},
1443+
},
1444+
},
1445+
},
1446+
},
14321447
{
14331448
Name: "Line type",
14341449
Skip: true,

0 commit comments

Comments
 (0)