diff options
| author | ckonstanski <carlos.konstanski@olo.com> | 2024-05-25 18:03:25 -0600 |
|---|---|---|
| committer | ckonstanski <carlos.konstanski@olo.com> | 2024-05-25 18:03:25 -0600 |
| commit | b8423f4d05c75094b7b9d09c6f0bb353acc9be1c (patch) | |
| tree | 3732f71f84191b26f038130c2220fb502d738251 /sql/functions/contact.get_contact_us_posts_by_id_and_read.sql | |
initial commit
Diffstat (limited to 'sql/functions/contact.get_contact_us_posts_by_id_and_read.sql')
| -rw-r--r-- | sql/functions/contact.get_contact_us_posts_by_id_and_read.sql | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sql/functions/contact.get_contact_us_posts_by_id_and_read.sql b/sql/functions/contact.get_contact_us_posts_by_id_and_read.sql new file mode 100644 index 0000000..646fe0f --- /dev/null +++ b/sql/functions/contact.get_contact_us_posts_by_id_and_read.sql @@ -0,0 +1,30 @@ +drop function contact.get_contact_us_posts_by_id_and_read ( + p_user_id bigint, + p_read bool +); + +create or replace function contact.get_contact_us_posts_by_id_and_read ( + p_user_id bigint, + p_read bool +) +returns setof contact.contact_us_posts +as $$ +begin + return query + select c.id, + c.first_name, + c.last_name, + c.email, + c.phone, + c.submitted, + c.comments + from contact.contact_us_posts c + left outer join contact.contact_us_posts_read cr + on c.id = cr.contact_us_post_id + where (p_read = false and cr.user_id is null) + or (p_read = true and cr.user_id = p_user_id) + order by c.submitted desc; + + return; +end; +$$ language plpgsql; |
