PostgreSQL does not allow set-returning functions in CASE statements
Running Davical version 1.1.7-1 with PostgreSQL version 10+190 on Ubuntu 18.04.
A user's own calendars are visible, but other resources are not visible.
Messages from Apache error log are: [Sat Nov 10 19:01:02.990809 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: Error: QF in '/usr/share/davical/inc/Principal.php' on line 224 [Sat Nov 10 19:01:02.990837 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: QF: SQL error "0A000" - ERROR: set-returning functions are not allowed in CASE LINE 4: ... expanded.g_id FROM (SELECT CASE WHEN $2 > 0 THEN expand_mem... ^ HINT: You might be able to move the set-returning function into a LATERAL FROM item. QUE [Sat Nov 10 19:01:02.990848 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: QF: RY: SELECT group_id FROM group_member WHERE member_id = $1 UNION SELECT expanded.g_id FROM (SELECT CASE WHEN $2 > 0 THEN expand_memberships( group_id, $2 - 1) END AS g_id FROM group_member WHERE member_id = $1) AS expanded WHERE expanded.g_ [Sat Nov 10 19:01:02.990857 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: QF: id IS NOT NULL; CONTEXT: SQL function "expand_memberships" during startup SQL statement "SELECT bit_or(subquery.privileges) FROM ( SELECT privileges FROM grants WHERE by_principal=in_grantor AND by_collection IS NULL AND (to_principal=in_ac [Sat Nov 10 19:01:02.990865 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: QF: cessor OR to_principal IN (SELECT expand_memberships(in_accessor,in_depth))) UNION SELECT 32::BIT(24) AS privileges FROM expand_memberships(in_accessor,in_depth) WHERE expand_memberships = in_grantor ) AS subquery" PL/pgSQL function pprivs( [Sat Nov 10 19:01:02.990873 2018] [php7:notice] [pid 27029] [client 88.96.123.86:58688] DAViCal: LOG: Principal: Query: QF: bigint,bigint,integer) line 14 at SQL statement"
Key errors seems to be: SQL error "0A000" - ERROR: set-returning functions are not allowed in CASE
This change in the set-returning functions is confirmed in the PostgreSQL release notes and SQL docs: https://www.postgresql.org/docs/devel/release-10.html#id-1.11.6.14.4 https://www.postgresql.org/docs/devel/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET
So I think that the set-returning functions in the CASE statements needs to be changed to allow Davical to run on PostgreSQL version 10. I'm not a Postgres DBA so I don't know what needs to be done to fix this problem, but do have several machines I can test changes on.