Skip to content

Instantly share code, notes, and snippets.

@nkaretnikov
Created April 17, 2015 19:44
Show Gist options
  • Save nkaretnikov/8c1f844941f62a806097 to your computer and use it in GitHub Desktop.
Save nkaretnikov/8c1f844941f62a806097 to your computer and use it in GitHub Desktop.
Notification preferences
id | user | type | delivery
----+------+---------------+----------
1 | 1 | NotifReply | Website
2 | 1 | NotifReply | Email
3 | 2 | NotifRethread | Website
4 | 3 | NotifWiki | Website
5 | 3 | NotifWiki | Email
@chreekat
Copy link

Here's one way:

select "user", type
from (
    select "user", type,  string_agg(delivery,',' order by delivery) preff
    from user_notification_pref
    group by type, "user"
) subq
where preff = 'NotifDeliverEmail,NotifDeliverWebsite';

@RhodiumToad
Copy link

select "user", type from user_notification_pref
group by type,"user"
having bool_or(delivery='Website') and bool_or(delivery='Email');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment