Skip to content

Commit 64e08fa

Browse files
committed
Merge pull request #5 from zhanghuangbin/pgsql_view
Add sample SQL template to create PostgreSQL VIEW for iRedMail server.
2 parents a5ebaa3 + f8ca22a commit 64e08fa

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

SQL/iredmail.pg.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--
2+
-- Notes:
3+
--
4+
-- * if you're running RHEL/CentOS 6 or 7, don't forget to uncomment lines
5+
-- under `Required by RHEL/CentOS X` to create dblink function.
6+
--
7+
-- * of course you should replace `xxx` in below sample SQL command by the
8+
-- real SQL username/password/database name.
9+
--
10+
-- * it's better to use SQL user `vmail` which has read-only permission to
11+
-- `vmail` database. Don't use `vmailadmin` or `postgres` user.
12+
13+
--
14+
-- Known issue on iRedMail server:
15+
--
16+
-- * Column `mailbox.created` stores timestamp when this account was created,
17+
-- if the timestamp contains timezone info (e.g. 2015-02-28 22:31:16.562376),
18+
-- this plugin cannot display any contact (causes SQL syntax error).
19+
-- Changing the timestamp to 2015-02-28 22:31:16 (without time zone info)
20+
-- fixes this issue.
21+
22+
--
23+
-- Required by RHEL/CentOS 6.
24+
--
25+
-- CREATE LANGUAGE plpgsql;
26+
-- \i /usr/share/pgsql/contrib/dblink.sql;
27+
28+
--
29+
-- Required by RHEL/CentOS 7
30+
--
31+
-- CREATE EXTENSION dblink;
32+
33+
CREATE VIEW global_addressbook AS
34+
SELECT * FROM dblink('host=127.0.0.1 port=5432 user=vmail password=xxx dbname=vmail', 'SELECT extract(epoch FROM created), name, username, domain FROM mailbox WHERE active=1')
35+
AS global_addressbook ("ID" BIGINT, name VARCHAR(255), email VARCHAR(255), domain VARCHAR(255));
36+
37+
ALTER TABLE global_addressbook OWNER TO roundcube;

0 commit comments

Comments
 (0)