Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Created January 25, 2017 14:56
Show Gist options
  • Save tlaitinen/0d842ea4255de1752436f7ef49a40036 to your computer and use it in GitHub Desktop.
Save tlaitinen/0d842ea4255de1752436f7ef49a40036 to your computer and use it in GitHub Desktop.
CREATE FUNCTION has_role (userId BIGINT, userGroupId BIGINT, role TEXT)
RETURNS BOOLEAN
AS
$$
SELECT EXISTS (
SELECT 1
FROM role
WHERE user_id = $1
AND user_group_id = $2
AND role = $3
AND active = true
)
$$
LANGUAGE SQL
STABLE
STRICT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment