Skip to content

Commit cddd637

Browse files
committed
fix: cast jsonb_array_length to INTEGER to match PostgreSQL's int4 return type
PostgreSQL's jsonb_array_length() returns INTEGER (int4, OID 23), not BIGINT. The previous BIGINT cast was incorrect and caused test failures. Changes: - query_remapper_function.go: Changed CAST to INTEGER instead of BIGINT - query_handler_test.go: Updated test expectations from Int8OID to Int4OID
1 parent 8bb197e commit cddd637

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎src/server/query_handler_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestHandleQuery(t *testing.T) {
195195
},
196196
"SELECT jsonb_array_length('[1, 2, 3]'::jsonb)": {
197197
"description": {"jsonb_array_length"},
198-
"types": {uint32ToString(pgtype.XID8OID)},
198+
"types": {uint32ToString(pgtype.Int4OID)},
199199
"values": {"3"},
200200
},
201201
"SELECT jsonb_pretty('{\"key\": \"value\"}'::JSONB)": {
@@ -265,7 +265,7 @@ func TestHandleQuery(t *testing.T) {
265265
},
266266
"SELECT jsonb_array_length(COALESCE('[]'::jsonb, '{}'::jsonb)) AS length": {
267267
"description": {"length"},
268-
"types": {uint32ToString(pgtype.Int8OID)},
268+
"types": {uint32ToString(pgtype.Int4OID)},
269269
"values": {"0"},
270270
},
271271
"SELECT * FROM pg_catalog.pg_stat_gssapi": {

‎src/server/query_remapper_function.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func CreatePgCatalogMacroQueries(config *Config) []string {
4242
ELSE json_extract_path_text(from_json, path_elems)::varchar
4343
END`,
4444
`CREATE MACRO jsonb_object_agg(key, value) AS to_json(map(array_agg(key), array_agg(value)))`,
45-
`CREATE MACRO jsonb_array_length(json) AS CAST(json_array_length(json) AS BIGINT)`,
45+
`CREATE MACRO jsonb_array_length(json) AS CAST(json_array_length(json) AS INTEGER)`,
4646
`CREATE MACRO jsonb_pretty(json) AS json_pretty(json)`,
4747
`CREATE MACRO json_array_elements(json) AS unnest(json_extract(json, '$[*]'))`,
4848
`CREATE MACRO jsonb_array_elements(json) AS unnest(json_extract(json, '$[*]'))`,

0 commit comments

Comments
 (0)