blob: 2329f26642953d197c322fb5576cf394476bdcc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
drop function contact.mark_contact_us_post (
p_contact_us_post_id int,
p_user_id int,
p_read_p bool
);
create or replace function contact.mark_contact_us_post (
p_contact_us_post_id int,
p_user_id int,
p_read_p bool
)
returns void
as $$
declare
l_id bigint;
begin
if(p_read_p) then
select id into l_id
from contact.contact_us_posts_read
where contact_us_post_id = p_contact_us_post_id
and user_id = p_user_id;
if(l_id is null) then
insert into contact.contact_us_posts_read (
contact_us_post_id,
user_id
) values (
p_contact_us_post_id,
p_user_id
);
end if;
else
delete from contact.contact_us_posts_read
where contact_us_post_id = p_contact_us_post_id
and user_id = p_user_id;
end if;
end;
$$ language plpgsql;
do $$declare
l_id bigint;
p_contact_us_post_id int := 1;
p_user_id int := 1;
p_read_p bool := 't';
begin
if(p_read_p) then
select id into l_id
from contact.contact_us_posts_read
where contact_us_post_id = p_contact_us_post_id
and user_id = p_user_id;
if(l_id is null) then
insert into contact.contact_us_posts_read (
contact_us_post_id,
user_id
) values (
p_contact_us_post_id,
p_user_id
);
end if;
else
delete from contact.contact_us_posts_read
where contact_us_post_id = p_contact_us_post_id
and user_id = p_user_id;
end if;
end$$;
|