Skip to content

Commit

Permalink
Fix jsonb_extract_path_text() if it has a VARIADIC array arg
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Feb 26, 2025
1 parent 92da811 commit 7a14088
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
VERSION = "0.35.1"
VERSION = "0.35.2"

ENV_PORT = "BEMIDB_PORT"
ENV_DATABASE = "BEMIDB_DATABASE"
Expand Down
5 changes: 5 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func TestHandleQuery(t *testing.T) {
"types": {Uint32ToString(pgtype.TextOID)},
"values": {"value"},
},
"SELECT jsonb_extract_path_text(json_column, VARIADIC ARRAY['key']) AS jsonb_extract_path_text FROM test_table LIMIT 1": {
"description": {"jsonb_extract_path_text"},
"types": {Uint32ToString(pgtype.TextOID)},
"values": {"value"},
},
"SELECT encode(sha256('foo'), 'hex'::text) AS encode": {
"description": {"encode"},
"types": {Uint32ToString(pgtype.TextOID)},
Expand Down
6 changes: 5 additions & 1 deletion src/query_remapper_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func CreatePgCatalogMacroQueries(config *Config) []string {
"CREATE MACRO row_to_json(record) AS to_json(record), (record, pretty_bool) AS to_json(record)",
"CREATE MACRO set_config(setting_name, new_value, is_local) AS new_value",
"CREATE MACRO version() AS 'PostgreSQL " + PG_VERSION + ", compiled by BemiDB'",
"CREATE MACRO jsonb_extract_path_text(from_json, path_elems) AS json_extract_path_text(from_json, path_elems)",
`CREATE MACRO jsonb_extract_path_text(from_json, path_elems) AS
CASE typeof(path_elems) LIKE '%[]'
WHEN true THEN json_extract_path_text(from_json, path_elems)[1]::varchar
ELSE json_extract_path_text(from_json, path_elems)::varchar
END`,
`CREATE MACRO json_build_object(k1, v1) AS json_object(k1, v1),
(k1, v1, k2, v2) AS json_object(k1, v1, k2, v2),
(k1, v1, k2, v2, k3, v3) AS json_object(k1, v1, k2, v2, k3, v3),
Expand Down

0 comments on commit 7a14088

Please sign in to comment.