Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitffac9f6

Browse files
committed
Fix incorrect declaration of citext's regexp_matches() functions.
These functions should return SETOF TEXT[], like the core functions theyare wrappers for; but they were incorrectly declared as returning justTEXT[]. This mistake had two results: first, if there was no match you gota scalar null result, whereas what you should get is an empty set (zerorows). Second, the 'g' flag was effectively ignored, since you would getonly one result array even if there were multiple matches, as reported byJeff Certain.While ignoring 'g' is a clear bug, the behavior for no matches might wellhave been thought to be the intended behavior by people who hadn't comparedit carefully to the core regexp_matches() functions. So we should treadcarefully about introducing this change in the back branches. Still, itclearly is a bug and so providing some fix is desirable.After discussion, the conclusion was to introduce the change in a 1.1version of the citext extension (as we would need to do anyway); 1.0 stillcontains the incorrect behavior. 1.1 is the default and only availableversion in HEAD, but it is optional in the back branches, where 1.0 remainsthe default version. People wishing to adopt the fix in back branches willneed to explicitly do ALTER EXTENSION citext UPDATE TO '1.1'. (I alsoprovided a downgrade script in the back branches, so people could go backto 1.0 if necessary.)This should be called out as an incompatible change in the 9.5 releasenotes, although we'll also document it in the next set of back-branchrelease notes. The notes should mention that any views or rules that usecitext's regexp_matches() functions will need to be dropped beforeupgrading to 1.1, and then recreated again afterwards.Back-patch to 9.1. The bug goes all the way back to citext's introductionin 8.4, but pre-9.1 there is no extension mechanism with which to managethe change. Given the lack of previous complaints it seems unnecessary tochange this behavior in 9.0, anyway.
1 parent6fd6669 commitffac9f6

File tree

4 files changed

+534
-1
lines changed

4 files changed

+534
-1
lines changed

‎contrib/citext/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
MODULES = citext
44

55
EXTENSION = citext
6-
DATA = citext--1.0.sql citext--unpackaged--1.0.sql
6+
DATA = citext--1.0.sql citext--1.1.sql citext--1.0--1.1.sql\
7+
citext--1.1--1.0.sql citext--unpackaged--1.0.sql
8+
PGFILEDESC = "citext - case-insensitive character string data type"
79

810
REGRESS = citext
911

‎contrib/citext/citext--1.0--1.1.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* contrib/citext/citext--1.0--1.1.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use"ALTER EXTENSION citext UPDATE TO '1.1'" to load this file. \quit
5+
6+
/* First we have to remove them from the extension*/
7+
ALTER EXTENSION citext DROP FUNCTION regexp_matches( citext, citext );
8+
ALTER EXTENSION citext DROP FUNCTION regexp_matches( citext, citext,text );
9+
10+
/* Then we can drop them*/
11+
DROPFUNCTION regexp_matches( citext, citext );
12+
DROPFUNCTION regexp_matches( citext, citext,text );
13+
14+
/* Now redefine*/
15+
CREATEFUNCTIONregexp_matches( citext, citext ) RETURNS SETOFTEXT[]AS $$
16+
SELECTpg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text,'i' );
17+
$$ LANGUAGE SQL IMMUTABLE STRICT ROWS1;
18+
19+
CREATEFUNCTIONregexp_matches( citext, citext,text ) RETURNS SETOFTEXT[]AS $$
20+
SELECTpg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHENpg_catalog.strpos($3,'c')=0 THEN $3||'i' ELSE $3 END );
21+
$$ LANGUAGE SQL IMMUTABLE STRICT ROWS10;

‎contrib/citext/citext--1.1--1.0.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* contrib/citext/citext--1.1--1.0.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use"ALTER EXTENSION citext UPDATE TO '1.0'" to load this file. \quit
5+
6+
/* First we have to remove them from the extension*/
7+
ALTER EXTENSION citext DROP FUNCTION regexp_matches( citext, citext );
8+
ALTER EXTENSION citext DROP FUNCTION regexp_matches( citext, citext,text );
9+
10+
/* Then we can drop them*/
11+
DROPFUNCTION regexp_matches( citext, citext );
12+
DROPFUNCTION regexp_matches( citext, citext,text );
13+
14+
/* Now redefine*/
15+
CREATEFUNCTIONregexp_matches( citext, citext ) RETURNSTEXT[]AS $$
16+
SELECTpg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text,'i' );
17+
$$ LANGUAGE SQL IMMUTABLE STRICT;
18+
19+
CREATEFUNCTIONregexp_matches( citext, citext,text ) RETURNSTEXT[]AS $$
20+
SELECTpg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHENpg_catalog.strpos($3,'c')=0 THEN $3||'i' ELSE $3 END );
21+
$$ LANGUAGE SQL IMMUTABLE STRICT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp