Lines 1-59
Link Here
|
1 |
From 39001794a3121c33c8cba50398b653a94328be40 Mon Sep 17 00:00:00 2001 |
|
|
2 |
From: Florian Schlichting <fsfs@debian.org> |
3 |
Date: Tue, 3 Oct 2017 22:36:29 +0200 |
4 |
Subject: [PATCH] Update caldav_functions.sql for Postgresql 10 |
5 |
|
6 |
From version 10, Postgresql does not allow set-returning functions in |
7 |
CASE statements. As we're using the functions recursively, we cannot |
8 |
use LATERAL as suggested in the error message, but we can switch the |
9 |
condition inside-out with only a limited amount of repetition. |
10 |
|
11 |
--- dba/caldav_functions.sql |
12 |
+++ dba/caldav_functions.sql |
13 |
@@ -897,21 +897,37 @@ LANGUAGE plpgsql IMMUTABLE STRICT; |
14 |
|
15 |
-- Expanded group memberships out to some depth |
16 |
CREATE or REPLACE FUNCTION expand_memberships( INT8, INT ) RETURNS SETOF INT8 AS $$ |
17 |
- SELECT group_id FROM group_member WHERE member_id = $1 |
18 |
- UNION |
19 |
- SELECT expanded.g_id FROM (SELECT CASE WHEN $2 > 0 THEN expand_memberships( group_id, $2 - 1) END AS g_id |
20 |
- FROM group_member WHERE member_id = $1) AS expanded |
21 |
- WHERE expanded.g_id IS NOT NULL; |
22 |
-$$ LANGUAGE sql STABLE STRICT; |
23 |
+BEGIN |
24 |
+ IF $2 > 0 THEN |
25 |
+ RETURN QUERY |
26 |
+ SELECT group_id FROM group_member WHERE member_id = $1 |
27 |
+ UNION |
28 |
+ SELECT expanded.g_id FROM (SELECT expand_memberships( group_id, $2 - 1) AS g_id |
29 |
+ FROM group_member WHERE member_id = $1) AS expanded |
30 |
+ WHERE expanded.g_id IS NOT NULL; |
31 |
+ ELSE |
32 |
+ RETURN QUERY |
33 |
+ SELECT group_id FROM group_member WHERE member_id = $1; |
34 |
+ END IF; |
35 |
+END |
36 |
+$$ LANGUAGE plpgsql IMMUTABLE STRICT; |
37 |
|
38 |
-- Expanded group members out to some depth |
39 |
CREATE or REPLACE FUNCTION expand_members( INT8, INT ) RETURNS SETOF INT8 AS $$ |
40 |
- SELECT member_id FROM group_member WHERE group_id = $1 |
41 |
- UNION |
42 |
- SELECT expanded.m_id FROM (SELECT CASE WHEN $2 > 0 THEN expand_members( member_id, $2 - 1) END AS m_id |
43 |
- FROM group_member WHERE group_id = $1) AS expanded |
44 |
- WHERE expanded.m_id IS NOT NULL; |
45 |
-$$ LANGUAGE sql STABLE STRICT; |
46 |
+BEGIN |
47 |
+ IF $2 > 0 THEN |
48 |
+ RETURN QUERY |
49 |
+ SELECT member_id FROM group_member WHERE group_id = $1 |
50 |
+ UNION |
51 |
+ SELECT expanded.m_id FROM (SELECT expand_members( member_id, $2 - 1) AS m_id |
52 |
+ FROM group_member WHERE group_id = $1) AS expanded |
53 |
+ WHERE expanded.m_id IS NOT NULL; |
54 |
+ ELSE |
55 |
+ RETURN QUERY |
56 |
+ SELECT member_id FROM group_member WHERE group_id = $1; |
57 |
+ END IF; |
58 |
+END |
59 |
+$$ LANGUAGE plpgsql IMMUTABLE STRICT; |