Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: query principal (#17273)

ecmadao1e9ff3eb4565
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 2a6d9163d0..24be20dd74 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -241,8 +241,12 @@ func listUserImpl(ctx context.Context, txn *sql.Tx, find *FindUserMessage) ([]*U
// Join the user_group table to find groups for each user.
// The user will be stored in the user_group.payload.members.member field, the member is in the "users/{id}" format
- query := with + `
- WITH user_groups AS (
+ if strings.HasPrefix(with, "WITH") {
+ with += ","
+ } else {
+ with = "WITH"
+ }
+ query := with + ` user_groups AS (
SELECT
principal.id AS user_id,
COALESCE(ARRAY_AGG(user_group.email ORDER BY user_group.email) FILTER (WHERE user_group.email IS NOT NULL), '{}') AS groups