Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c45af8f

Browse files
committed
Fix citext upgrade script for disallowance of oidvector element assignment.
In commit 45e02e3, we intentionally disallowed updates on individual elements of oidvector columns. While that still seems like a sane idea in the abstract, we (I) forgot that citext's "upgrade from unpackaged" script did in fact perform exactly such updates, in order to fix the problem that citext indexes should have a collation but would not in databases dumped or upgraded from pre-9.1 installations. Even if we wanted to add casts to allow such updates, there's no practical way to do so in the back branches, so the only real alternative is to make citext's kluge even klugier. In this patch, I cast the oidvector to text, fix its contents with regexp_replace, and cast back to oidvector. (Ugh!) Since the aforementioned commit went into all active branches, we have to fix this in all branches that contain the now-broken update script. Per report from Eric Malm.
1 parent eeab936 commit c45af8f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

contrib/citext/citext--unpackaged--1.0.sql

+20-8
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ UPDATE pg_catalog.pg_attribute SET attcollation = 100
105105
FROM typeoids
106106
WHERE atttypid = typeoids.typoid;
107107

108-
UPDATE pg_catalog.pg_index SET indcollation[0] = 100
108+
-- Updating the index indcollations is particularly tedious, but since we
109+
-- don't currently allow SQL assignment to individual elements of oidvectors,
110+
-- there's little choice.
111+
112+
UPDATE pg_catalog.pg_index SET indcollation =
113+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, '^0', '100')::pg_catalog.oidvector
109114
WHERE indclass[0] IN (
110115
WITH RECURSIVE typeoids(typoid) AS
111116
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -115,7 +120,8 @@ WHERE indclass[0] IN (
115120
WHERE opcintype = typeoids.typoid
116121
);
117122

118-
UPDATE pg_catalog.pg_index SET indcollation[1] = 100
123+
UPDATE pg_catalog.pg_index SET indcollation =
124+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+) 0', E'\\1 100')::pg_catalog.oidvector
119125
WHERE indclass[1] IN (
120126
WITH RECURSIVE typeoids(typoid) AS
121127
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -125,7 +131,8 @@ WHERE indclass[1] IN (
125131
WHERE opcintype = typeoids.typoid
126132
);
127133

128-
UPDATE pg_catalog.pg_index SET indcollation[2] = 100
134+
UPDATE pg_catalog.pg_index SET indcollation =
135+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
129136
WHERE indclass[2] IN (
130137
WITH RECURSIVE typeoids(typoid) AS
131138
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -135,7 +142,8 @@ WHERE indclass[2] IN (
135142
WHERE opcintype = typeoids.typoid
136143
);
137144

138-
UPDATE pg_catalog.pg_index SET indcollation[3] = 100
145+
UPDATE pg_catalog.pg_index SET indcollation =
146+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
139147
WHERE indclass[3] IN (
140148
WITH RECURSIVE typeoids(typoid) AS
141149
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -145,7 +153,8 @@ WHERE indclass[3] IN (
145153
WHERE opcintype = typeoids.typoid
146154
);
147155

148-
UPDATE pg_catalog.pg_index SET indcollation[4] = 100
156+
UPDATE pg_catalog.pg_index SET indcollation =
157+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+ \\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
149158
WHERE indclass[4] IN (
150159
WITH RECURSIVE typeoids(typoid) AS
151160
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -155,7 +164,8 @@ WHERE indclass[4] IN (
155164
WHERE opcintype = typeoids.typoid
156165
);
157166

158-
UPDATE pg_catalog.pg_index SET indcollation[5] = 100
167+
UPDATE pg_catalog.pg_index SET indcollation =
168+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+ \\d+ \\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
159169
WHERE indclass[5] IN (
160170
WITH RECURSIVE typeoids(typoid) AS
161171
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -165,7 +175,8 @@ WHERE indclass[5] IN (
165175
WHERE opcintype = typeoids.typoid
166176
);
167177

168-
UPDATE pg_catalog.pg_index SET indcollation[6] = 100
178+
UPDATE pg_catalog.pg_index SET indcollation =
179+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+ \\d+ \\d+ \\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
169180
WHERE indclass[6] IN (
170181
WITH RECURSIVE typeoids(typoid) AS
171182
( SELECT 'citext'::pg_catalog.regtype UNION
@@ -175,7 +186,8 @@ WHERE indclass[6] IN (
175186
WHERE opcintype = typeoids.typoid
176187
);
177188

178-
UPDATE pg_catalog.pg_index SET indcollation[7] = 100
189+
UPDATE pg_catalog.pg_index SET indcollation =
190+
pg_catalog.regexp_replace(indcollation::pg_catalog.text, E'^(\\d+ \\d+ \\d+ \\d+ \\d+ \\d+ \\d+) 0', E'\\1 100')::pg_catalog.oidvector
179191
WHERE indclass[7] IN (
180192
WITH RECURSIVE typeoids(typoid) AS
181193
( SELECT 'citext'::pg_catalog.regtype UNION

0 commit comments

Comments
 (0)