forked from jconway/plr
-
Notifications
You must be signed in to change notification settings - Fork 27
/
plr--8.4.7.sql
112 lines (93 loc) · 2.94 KB
/
plr--8.4.7.sql
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
CREATE FUNCTION plr_call_handler()
RETURNS LANGUAGE_HANDLER
AS 'MODULE_PATHNAME' LANGUAGE C;
CREATE FUNCTION plr_inline_handler(internal)
RETURNS VOID
AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
CREATE FUNCTION plr_validator(oid)
RETURNS VOID
AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
CREATE LANGUAGE plr
HANDLER plr_call_handler
INLINE plr_inline_handler
VALIDATOR plr_validator;
CREATE OR REPLACE FUNCTION plr_version ()
RETURNS text
AS 'MODULE_PATHNAME','plr_version'
LANGUAGE C;
CREATE OR REPLACE FUNCTION reload_plr_modules ()
RETURNS text
AS 'MODULE_PATHNAME','reload_plr_modules'
LANGUAGE C;
CREATE OR REPLACE FUNCTION install_rcmd (text)
RETURNS text
AS 'MODULE_PATHNAME','install_rcmd'
LANGUAGE C STRICT;
REVOKE EXECUTE ON FUNCTION install_rcmd (text) FROM PUBLIC;
CREATE OR REPLACE FUNCTION plr_singleton_array (float8)
RETURNS float8[]
AS 'MODULE_PATHNAME','plr_array'
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION plr_array_push (_float8, float8)
RETURNS float8[]
AS 'MODULE_PATHNAME','plr_array_push'
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION plr_array_accum (_float8, float8)
RETURNS float8[]
AS 'MODULE_PATHNAME','plr_array_accum'
LANGUAGE C;
CREATE TYPE plr_environ_type AS (name text, value text);
CREATE OR REPLACE FUNCTION plr_environ ()
RETURNS SETOF plr_environ_type
AS 'MODULE_PATHNAME','plr_environ'
LANGUAGE C;
REVOKE EXECUTE ON FUNCTION plr_environ() FROM PUBLIC;
CREATE TYPE r_typename AS (typename text, typeoid oid);
CREATE OR REPLACE FUNCTION r_typenames()
RETURNS SETOF r_typename AS '
within(data.frame(
typename = ls(name = .GlobalEnv, pat = "OID"),
stringsAsFactors = FALSE
),
{
typeoid <- sapply(typename, get)
})
' language 'plr';
CREATE OR REPLACE FUNCTION load_r_typenames()
RETURNS text AS '
sql <- "select upper(typname::text) || ''OID'' as typename, oid from pg_catalog.pg_type where typtype = ''b'' order by typname"
rs <- pg.spi.exec(sql)
for(i in 1:nrow(rs))
{
typobj <- rs[i,1]
typval <- rs[i,2]
if (substr(typobj,1,1) == "_")
typobj <- paste("ARRAYOF", substr(typobj,2,nchar(typobj)), sep="")
assign(typobj, typval, .GlobalEnv)
}
return("OK")
' language 'plr';
CREATE TYPE r_version_type AS (name text, value text);
CREATE OR REPLACE FUNCTION r_version()
RETURNS setof r_version_type as '
cbind(names(version),unlist(version))
' language 'plr';
CREATE OR REPLACE FUNCTION plr_set_rhome (text)
RETURNS text
AS 'MODULE_PATHNAME','plr_set_rhome'
LANGUAGE C STRICT;
REVOKE EXECUTE ON FUNCTION plr_set_rhome (text) FROM PUBLIC;
CREATE OR REPLACE FUNCTION plr_unset_rhome ()
RETURNS text
AS 'MODULE_PATHNAME','plr_unset_rhome'
LANGUAGE C;
REVOKE EXECUTE ON FUNCTION plr_unset_rhome () FROM PUBLIC;
CREATE OR REPLACE FUNCTION plr_set_display (text)
RETURNS text
AS 'MODULE_PATHNAME','plr_set_display'
LANGUAGE C STRICT;
REVOKE EXECUTE ON FUNCTION plr_set_display (text) FROM PUBLIC;
CREATE OR REPLACE FUNCTION plr_get_raw (bytea)
RETURNS bytea
AS 'MODULE_PATHNAME','plr_get_raw'
LANGUAGE C STRICT;