Files
expenses/server/migrations/20260918000002_create_accessible_accounts.sql

11 lines
320 B
PL/PgSQL

CREATE FUNCTION accessible_accounts (p_user_id UUID) RETURNS SETOF accounts LANGUAGE sql STABLE AS $$
SELECT accounts.*
FROM accounts
WHERE EXISTS (
SELECT 1
FROM account_members
WHERE account_members.account_id = accounts.id
AND account_members.user_id = p_user_id
)
$$;