author | Julien Cristau <julien.cristau@logilab.fr> |
Wed, 02 Apr 2014 17:03:46 +0200 | |
changeset 9644 | 2683c9f9a6b7 |
parent 9419 | 3e6a1791339d |
child 10327 | a504a7840915 |
permissions | -rw-r--r-- |
4321 | 1 |
/* -*- sql -*- |
0 | 2 |
|
4321 | 3 |
postgres specific registered procedures, |
4 |
require the plpgsql language installed |
|
0 | 5 |
|
6 |
*/ |
|
7 |
||
4126
2eb47c1efee1
make cubicweb-ctl db-init -d work with postgresql backend
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3928
diff
changeset
|
8 |
DROP FUNCTION IF EXISTS comma_join (anyarray) CASCADE; |
0 | 9 |
CREATE FUNCTION comma_join (anyarray) RETURNS text AS $$ |
10 |
SELECT array_to_string($1, ', ') |
|
11 |
$$ LANGUAGE SQL;; |
|
12 |
||
9364
73bd5012336f
Make the GROUP_CONCAT aggregate function not repeat values (closes #3223975)
Julien Cristau <julien.cristau@logilab.fr>
parents:
4321
diff
changeset
|
13 |
|
73bd5012336f
Make the GROUP_CONCAT aggregate function not repeat values (closes #3223975)
Julien Cristau <julien.cristau@logilab.fr>
parents:
4321
diff
changeset
|
14 |
CREATE FUNCTION cw_array_append_unique (anyarray, anyelement) RETURNS anyarray AS $$ |
73bd5012336f
Make the GROUP_CONCAT aggregate function not repeat values (closes #3223975)
Julien Cristau <julien.cristau@logilab.fr>
parents:
4321
diff
changeset
|
15 |
SELECT array_append($1, (SELECT $2 WHERE $2 <> ALL($1))) |
9419
3e6a1791339d
[schema/stored procs] fix syntax error (closes #3450362)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9364
diff
changeset
|
16 |
$$ LANGUAGE SQL;; |
9364
73bd5012336f
Make the GROUP_CONCAT aggregate function not repeat values (closes #3223975)
Julien Cristau <julien.cristau@logilab.fr>
parents:
4321
diff
changeset
|
17 |
|
4126
2eb47c1efee1
make cubicweb-ctl db-init -d work with postgresql backend
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3928
diff
changeset
|
18 |
DROP AGGREGATE IF EXISTS group_concat (anyelement) CASCADE; |
0 | 19 |
CREATE AGGREGATE group_concat ( |
20 |
basetype = anyelement, |
|
9364
73bd5012336f
Make the GROUP_CONCAT aggregate function not repeat values (closes #3223975)
Julien Cristau <julien.cristau@logilab.fr>
parents:
4321
diff
changeset
|
21 |
sfunc = cw_array_append_unique, |
0 | 22 |
stype = anyarray, |
23 |
finalfunc = comma_join, |
|
24 |
initcond = '{}' |
|
25 |
);; |
|
26 |
||
27 |
||
28 |
||
4126
2eb47c1efee1
make cubicweb-ctl db-init -d work with postgresql backend
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3928
diff
changeset
|
29 |
DROP FUNCTION IF EXISTS limit_size (fulltext text, format text, maxsize integer); |
0 | 30 |
CREATE FUNCTION limit_size (fulltext text, format text, maxsize integer) RETURNS text AS $$ |
31 |
DECLARE |
|
32 |
plaintext text; |
|
33 |
BEGIN |
|
34 |
IF char_length(fulltext) < maxsize THEN |
|
35 |
RETURN fulltext; |
|
36 |
END IF; |
|
37 |
IF format = 'text/html' OR format = 'text/xhtml' OR format = 'text/xml' THEN |
|
38 |
plaintext := regexp_replace(fulltext, '<[\\w/][^>]+>', '', 'g'); |
|
39 |
ELSE |
|
40 |
plaintext := fulltext; |
|
41 |
END IF; |
|
42 |
IF char_length(plaintext) < maxsize THEN |
|
43 |
RETURN plaintext; |
|
44 |
ELSE |
|
45 |
RETURN substring(plaintext from 1 for maxsize) || '...'; |
|
46 |
END IF; |
|
47 |
END |
|
48 |
$$ LANGUAGE plpgsql;; |
|
49 |
||
4126
2eb47c1efee1
make cubicweb-ctl db-init -d work with postgresql backend
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3928
diff
changeset
|
50 |
DROP FUNCTION IF EXISTS text_limit_size (fulltext text, maxsize integer); |
0 | 51 |
CREATE FUNCTION text_limit_size (fulltext text, maxsize integer) RETURNS text AS $$ |
52 |
BEGIN |
|
53 |
RETURN limit_size(fulltext, 'text/plain', maxsize); |
|
54 |
END |
|
55 |
$$ LANGUAGE plpgsql;; |