-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplx--1.0.sql
More file actions
119 lines (95 loc) · 3.61 KB
/
Copy pathplx--1.0.sql
File metadata and controls
119 lines (95 loc) · 3.61 KB
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
112
113
114
115
116
117
118
119
/* plx 1.0: registers the plx dialect languages and the string-builder type */
\echo Use "CREATE EXTENSION plx" to load this file. \quit
/*
* plx_strbuild: an expanded-object string builder. Its flattened form is a
* text-compatible varlena, so it casts to and from text without a function.
* plx_sb_append grows the buffer in place across a loop (amortized O(1)),
* avoiding the quadratic cost of `s := s || 'x'` on plain text.
*/
CREATE TYPE plx_strbuild;
CREATE FUNCTION plx_sb_in(cstring) RETURNS plx_strbuild
AS '$libdir/plx', 'plx_sb_in' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION plx_sb_out(plx_strbuild) RETURNS cstring
AS '$libdir/plx', 'plx_sb_out' LANGUAGE C IMMUTABLE STRICT;
CREATE TYPE plx_strbuild (
INPUT = plx_sb_in,
OUTPUT = plx_sb_out,
LIKE = text,
STORAGE = extended
);
CREATE FUNCTION plx_sb_append_support(internal) RETURNS internal
AS '$libdir/plx', 'plx_sb_append_support' LANGUAGE C;
CREATE FUNCTION plx_sb_append(plx_strbuild, text) RETURNS plx_strbuild
AS '$libdir/plx', 'plx_sb_append' LANGUAGE C IMMUTABLE
SUPPORT plx_sb_append_support;
-- plx_strbuild is implicitly usable as text (so it works in RETURN, string
-- functions, and concatenation). text becomes a builder only in assignment
-- context, which avoids operator ambiguity such as `builder || text`.
CREATE CAST (plx_strbuild AS text) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (text AS plx_strbuild) WITHOUT FUNCTION AS ASSIGNMENT;
/*
* Runtime call handler = plpgsql's OWN handler. Binding a fresh pg_proc row to
* plpgsql.so's exported symbol is legal (CreateProceduralLanguage only checks
* the handler RETURNS language_handler). Execution is therefore 100% stock
* plpgsql; plx contributes zero call-path C.
*/
CREATE FUNCTION plx_call_handler()
RETURNS language_handler
AS '$libdir/plpgsql', 'plpgsql_call_handler'
LANGUAGE C;
/* Ruby dialect validator + inline handler live in plx.so */
CREATE FUNCTION plx_ruby_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_ruby_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_ruby_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_ruby_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxruby
HANDLER plx_call_handler
INLINE plx_ruby_inline_handler
VALIDATOR plx_ruby_validator;
COMMENT ON LANGUAGE plxruby IS 'plx Ruby dialect (transpiles to plpgsql)';
/* PHP dialect */
CREATE FUNCTION plx_php_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_php_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_php_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_php_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxphp
HANDLER plx_call_handler
INLINE plx_php_inline_handler
VALIDATOR plx_php_validator;
COMMENT ON LANGUAGE plxphp IS 'plx PHP dialect (transpiles to plpgsql)';
/* JavaScript dialect */
CREATE FUNCTION plx_js_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_js_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_js_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_js_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxjs
HANDLER plx_call_handler
INLINE plx_js_inline_handler
VALIDATOR plx_js_validator;
COMMENT ON LANGUAGE plxjs IS 'plx JavaScript dialect (transpiles to plpgsql)';
/* Python dialect */
CREATE FUNCTION plx_py_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_py_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_py_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_py_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxpython3
HANDLER plx_call_handler
INLINE plx_py_inline_handler
VALIDATOR plx_py_validator;
COMMENT ON LANGUAGE plxpython3 IS 'plx Python dialect (transpiles to plpgsql)';