Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/server/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestHandleQuery(t *testing.T) {
},
"SELECT jsonb_array_length('[1, 2, 3]'::jsonb)": {
"description": {"jsonb_array_length"},
"types": {uint32ToString(pgtype.XID8OID)},
"types": {uint32ToString(pgtype.Int4OID)},
"values": {"3"},
},
"SELECT jsonb_pretty('{\"key\": \"value\"}'::JSONB)": {
Expand Down Expand Up @@ -258,6 +258,16 @@ func TestHandleQuery(t *testing.T) {
"types": {uint32ToString(pgtype.TextOID)},
"values": {"bemidb"},
},
"SELECT COALESCE(NULL, '[]'::jsonb) AS json_value": {
"description": {"json_value"},
"types": {uint32ToString(pgtype.JSONOID)},
"values": {"[]"},
},
"SELECT jsonb_array_length(COALESCE('[]'::jsonb, '{}'::jsonb)) AS length": {
"description": {"length"},
"types": {uint32ToString(pgtype.Int4OID)},
"values": {"0"},
},
"SELECT * FROM pg_catalog.pg_stat_gssapi": {
"description": {"pid", "gss_authenticated", "principal", "encrypted", "credentials_delegated"},
"types": {uint32ToString(pgtype.Int4OID), uint32ToString(pgtype.BoolOID), uint32ToString(pgtype.TextOID), uint32ToString(pgtype.BoolOID), uint32ToString(pgtype.BoolOID)},
Expand Down
8 changes: 3 additions & 5 deletions src/server/query_remapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,9 @@ func (remapper *QueryRemapper) remappedExpressions(node *pgQuery.Node, remappedC
// COALESCE(value1, value2, ...)
coalesceExpr := node.GetCoalesceExpr()
if coalesceExpr != nil {
for _, arg := range coalesceExpr.Args {
if arg.GetSubLink() != nil {
// Nested SELECT
subSelect := arg.GetSubLink().Subselect.GetSelectStmt()
remapper.remapSelectStatement(subSelect, permissions, indentLevel+1) // recursion
for i, arg := range coalesceExpr.Args {
if arg != nil {
coalesceExpr.Args[i] = remapper.remappedExpressions(arg, remappedColumnRefs, permissions, indentLevel+1) // self-recursion
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/query_remapper_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func CreatePgCatalogMacroQueries(config *Config) []string {
ELSE json_extract_path_text(from_json, path_elems)::varchar
END`,
`CREATE MACRO jsonb_object_agg(key, value) AS to_json(map(array_agg(key), array_agg(value)))`,
`CREATE MACRO jsonb_array_length(json) AS json_array_length(json)`,
`CREATE MACRO jsonb_array_length(json) AS CAST(json_array_length(json) AS INTEGER)`,
`CREATE MACRO jsonb_pretty(json) AS json_pretty(json)`,
`CREATE MACRO json_array_elements(json) AS unnest(json_extract(json, '$[*]'))`,
`CREATE MACRO jsonb_array_elements(json) AS unnest(json_extract(json, '$[*]'))`,
Expand Down