-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplx--1.2.1.sql
More file actions
209 lines (165 loc) · 6.12 KB
/
Copy pathplx--1.2.1.sql
File metadata and controls
209 lines (165 loc) · 6.12 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* 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)';
/* COBOL dialect (ISO/IEC 1989:2023) validator + inline handler live in plx.so */
CREATE FUNCTION plx_cob_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_cob_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_cob_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_cob_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxcobol
HANDLER plx_call_handler
INLINE plx_cob_inline_handler
VALIDATOR plx_cob_validator;
COMMENT ON LANGUAGE plxcobol IS 'plx COBOL dialect (ISO/IEC 1989:2023, transpiles to plpgsql)';
/* PL/SQL dialect (Oracle) validator + inline handler live in plx.so */
CREATE FUNCTION plx_plsql_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_plsql_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_plsql_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_plsql_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxplsql
HANDLER plx_call_handler
INLINE plx_plsql_inline_handler
VALIDATOR plx_plsql_validator;
COMMENT ON LANGUAGE plxplsql IS 'plx Oracle PL/SQL dialect (transpiles to plpgsql)';
/* TypeScript dialect validator + inline handler live in plx.so */
CREATE FUNCTION plx_ts_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_ts_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_ts_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_ts_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxts
HANDLER plx_call_handler
INLINE plx_ts_inline_handler
VALIDATOR plx_ts_validator;
COMMENT ON LANGUAGE plxts IS 'plx TypeScript dialect (transpiles to plpgsql)';
/* T-SQL dialect (Transact-SQL) validator + inline handler live in plx.so */
CREATE FUNCTION plx_tsql_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_tsql_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_tsql_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_tsql_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxtsql
HANDLER plx_call_handler
INLINE plx_tsql_inline_handler
VALIDATOR plx_tsql_validator;
COMMENT ON LANGUAGE plxtsql IS 'plx Transact-SQL (SQL Server) dialect (transpiles to plpgsql)';
/* Go dialect validator + inline handler live in plx.so */
CREATE FUNCTION plx_go_validator(oid)
RETURNS void
AS '$libdir/plx', 'plx_go_validator'
LANGUAGE C STRICT;
CREATE FUNCTION plx_go_inline_handler(internal)
RETURNS void
AS '$libdir/plx', 'plx_go_inline_handler'
LANGUAGE C;
CREATE TRUSTED LANGUAGE plxgo
HANDLER plx_call_handler
INLINE plx_go_inline_handler
VALIDATOR plx_go_validator;
COMMENT ON LANGUAGE plxgo IS 'plx Go dialect (transpiles to plpgsql)';