-
Notifications
You must be signed in to change notification settings - Fork 0
/
lolor--1.0.sql
191 lines (167 loc) · 5.46 KB
/
lolor--1.0.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
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
/* contrib/lolor/lolor--1.1.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION lolor" to load this file. \quit
-- Replace pg_largeobject
CREATE TABLE lolor.pg_largeobject(
loid oid NOT NULL,
pageno int NOT NULL,
data bytea NOT NULL,
PRIMARY KEY(loid,pageno));
SELECT pg_catalog.pg_extension_config_dump('lolor.pg_largeobject', '');
-- Replace pg_largeobject_metadata
CREATE TABLE lolor.pg_largeobject_metadata(
oid oid NOT NULL,
lomowner oid NOT NULL,
lomacl aclitem[],
PRIMARY KEY(oid));
SELECT pg_catalog.pg_extension_config_dump('lolor.pg_largeobject_metadata', '');
-- Replace lo_open()
ALTER FUNCTION pg_catalog.lo_open(Oid, int4)
RENAME TO lo_open_orig;
CREATE FUNCTION pg_catalog.lo_open(Oid, int4)
RETURNS pg_catalog.int4
AS 'MODULE_PATHNAME', 'lolor_lo_open'
LANGUAGE C STRICT VOLATILE;
-- Replace lo_close()
ALTER FUNCTION pg_catalog.lo_close(int4)
RENAME TO lo_close_orig;
CREATE FUNCTION pg_catalog.lo_close(int4)
RETURNS pg_catalog.int4
AS 'MODULE_PATHNAME', 'lolor_lo_close'
LANGUAGE C STRICT VOLATILE;
-- lo_creat
ALTER FUNCTION pg_catalog.lo_creat(integer)
RENAME TO lo_creat_orig;
CREATE FUNCTION pg_catalog.lo_creat(integer)
RETURNS oid
AS 'MODULE_PATHNAME', 'lolor_lo_creat'
LANGUAGE C STRICT VOLATILE;
-- lo_create
ALTER FUNCTION pg_catalog.lo_create(oid)
RENAME TO lo_create_orig;
CREATE FUNCTION pg_catalog.lo_create(oid)
RETURNS oid
AS 'MODULE_PATHNAME', 'lolor_lo_create'
LANGUAGE C STRICT VOLATILE;
-- loread
ALTER FUNCTION pg_catalog.loread(integer, integer)
RENAME TO loread_orig;
CREATE FUNCTION pg_catalog.loread(integer, integer)
RETURNS bytea
AS 'MODULE_PATHNAME', 'lolor_loread'
LANGUAGE C STRICT VOLATILE;
-- lowrite
ALTER FUNCTION pg_catalog.lowrite(integer, bytea)
RENAME TO lowrite_orig;
CREATE FUNCTION pg_catalog.lowrite(integer, bytea)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lowrite'
LANGUAGE C STRICT VOLATILE;
-- lo_export
ALTER FUNCTION pg_catalog.lo_export(oid, text)
RENAME TO lo_export_orig;
CREATE FUNCTION pg_catalog.lo_export(oid, text)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_export'
LANGUAGE C STRICT VOLATILE;
-- lo_from_bytea
ALTER FUNCTION pg_catalog.lo_from_bytea(oid, bytea)
RENAME TO lo_from_bytea_orig;
CREATE FUNCTION pg_catalog.lo_from_bytea(oid, bytea)
RETURNS oid
AS 'MODULE_PATHNAME', 'lolor_lo_from_bytea'
LANGUAGE C STRICT VOLATILE;
-- lo_get
ALTER FUNCTION pg_catalog.lo_get(oid)
RENAME TO lo_get_orig;
CREATE FUNCTION pg_catalog.lo_get(oid)
RETURNS bytea
AS 'MODULE_PATHNAME', 'lolor_lo_get'
LANGUAGE C STRICT VOLATILE;
-- lo_get
ALTER FUNCTION pg_catalog.lo_get(oid, bigint, integer)
RENAME TO lo_get_orig;
CREATE FUNCTION pg_catalog.lo_get(oid, bigint, integer)
RETURNS bytea
AS 'MODULE_PATHNAME', 'lolor_lo_get_fragment'
LANGUAGE C STRICT VOLATILE;
-- lo_import
ALTER FUNCTION pg_catalog.lo_import(text)
RENAME TO lo_import_orig;
CREATE FUNCTION pg_catalog.lo_import(text)
RETURNS oid
AS 'MODULE_PATHNAME', 'lolor_lo_import'
LANGUAGE C STRICT VOLATILE;
-- lo_import
ALTER FUNCTION pg_catalog.lo_import(text, oid)
RENAME TO lo_import_orig;
CREATE FUNCTION pg_catalog.lo_import(text, oid)
RETURNS oid
AS 'MODULE_PATHNAME', 'lolor_lo_import_with_oid'
LANGUAGE C STRICT VOLATILE;
-- lo_lseek
ALTER FUNCTION pg_catalog.lo_lseek(integer, integer, integer)
RENAME TO lo_lseek_orig;
CREATE FUNCTION pg_catalog.lo_lseek(integer, integer, integer)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_lseek'
LANGUAGE C STRICT VOLATILE;
-- lo_lseek64
ALTER FUNCTION pg_catalog.lo_lseek64(integer, bigint, integer)
RENAME TO lo_lseek64_orig;
CREATE FUNCTION pg_catalog.lo_lseek64(integer, bigint, integer)
RETURNS bigint
AS 'MODULE_PATHNAME', 'lolor_lo_lseek64'
LANGUAGE C STRICT VOLATILE;
-- lo_put
ALTER FUNCTION pg_catalog.lo_put(oid, bigint, bytea)
RENAME TO lo_put_orig;
CREATE FUNCTION pg_catalog.lo_put(oid, bigint, bytea)
RETURNS void
AS 'MODULE_PATHNAME', 'lolor_lo_put'
LANGUAGE C STRICT VOLATILE;
-- lo_tell
ALTER FUNCTION pg_catalog.lo_tell(integer)
RENAME TO lo_tell_orig;
CREATE FUNCTION pg_catalog.lo_tell(integer)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_tell'
LANGUAGE C STRICT VOLATILE;
-- lo_tell64
ALTER FUNCTION pg_catalog.lo_tell64(integer)
RENAME TO lo_tell64_orig;
CREATE FUNCTION pg_catalog.lo_tell64(integer)
RETURNS bigint
AS 'MODULE_PATHNAME', 'lolor_lo_tell64'
LANGUAGE C STRICT VOLATILE;
-- lo_truncate
ALTER FUNCTION pg_catalog.lo_truncate(integer, integer)
RENAME TO lo_truncate_orig;
CREATE FUNCTION pg_catalog.lo_truncate(integer, integer)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_truncate'
LANGUAGE C STRICT VOLATILE;
-- lo_truncate64
ALTER FUNCTION pg_catalog.lo_truncate64(integer, bigint)
RENAME TO lo_truncate64_orig;
CREATE FUNCTION pg_catalog.lo_truncate64(integer, bigint)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_truncate64'
LANGUAGE C STRICT VOLATILE;
-- lo_unlink
ALTER FUNCTION pg_catalog.lo_unlink(oid)
RENAME TO lo_unlink_orig;
CREATE FUNCTION pg_catalog.lo_unlink(oid)
RETURNS integer
AS 'MODULE_PATHNAME', 'lolor_lo_unlink'
LANGUAGE C STRICT VOLATILE;
-- Create the trigger that will fire on DROP EXTENSION
-- to perform cleanup
CREATE FUNCTION pg_catalog.lo_on_drop_extension()
RETURNS pg_catalog.event_trigger
AS 'MODULE_PATHNAME', 'lolor_on_drop_extension'
LANGUAGE C VOLATILE;
CREATE EVENT TRIGGER lo_on_drop_extension
ON ddl_command_start WHEN tag IN ('DROP EXTENSION')
EXECUTE FUNCTION pg_catalog.lo_on_drop_extension();
ALTER EVENT TRIGGER lo_on_drop_extension ENABLE ALWAYS;