@@ -18,7 +18,7 @@ PG_MODULE_MAGIC;
18
18
* ====================
19
19
*/
20
20
21
- static int32 citextcmp (text * left , text * right );
21
+ static int32 citextcmp (text * left , text * right , Oid collid );
22
22
extern Datum citext_cmp (PG_FUNCTION_ARGS );
23
23
extern Datum citext_hash (PG_FUNCTION_ARGS );
24
24
extern Datum citext_eq (PG_FUNCTION_ARGS );
@@ -42,17 +42,18 @@ extern Datum citext_larger(PG_FUNCTION_ARGS);
42
42
* Returns int32 negative, zero, or positive.
43
43
*/
44
44
static int32
45
- citextcmp (text * left , text * right )
45
+ citextcmp (text * left , text * right , Oid collid )
46
46
{
47
47
char * lcstr ,
48
48
* rcstr ;
49
49
int32 result ;
50
50
51
- lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ));
52
- rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ));
51
+ lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ), collid );
52
+ rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ), collid );
53
53
54
54
result = varstr_cmp (lcstr , strlen (lcstr ),
55
- rcstr , strlen (rcstr ));
55
+ rcstr , strlen (rcstr ),
56
+ collid );
56
57
57
58
pfree (lcstr );
58
59
pfree (rcstr );
@@ -75,7 +76,7 @@ citext_cmp(PG_FUNCTION_ARGS)
75
76
text * right = PG_GETARG_TEXT_PP (1 );
76
77
int32 result ;
77
78
78
- result = citextcmp (left , right );
79
+ result = citextcmp (left , right , PG_GET_COLLATION () );
79
80
80
81
PG_FREE_IF_COPY (left , 0 );
81
82
PG_FREE_IF_COPY (right , 1 );
@@ -92,7 +93,7 @@ citext_hash(PG_FUNCTION_ARGS)
92
93
char * str ;
93
94
Datum result ;
94
95
95
- str = str_tolower (VARDATA_ANY (txt ), VARSIZE_ANY_EXHDR (txt ));
96
+ str = str_tolower (VARDATA_ANY (txt ), VARSIZE_ANY_EXHDR (txt ), PG_GET_COLLATION () );
96
97
result = hash_any ((unsigned char * ) str , strlen (str ));
97
98
pfree (str );
98
99
@@ -121,8 +122,8 @@ citext_eq(PG_FUNCTION_ARGS)
121
122
122
123
/* We can't compare lengths in advance of downcasing ... */
123
124
124
- lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ));
125
- rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ));
125
+ lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ), PG_GET_COLLATION () );
126
+ rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ), PG_GET_COLLATION () );
126
127
127
128
/*
128
129
* Since we only care about equality or not-equality, we can avoid all the
@@ -151,8 +152,8 @@ citext_ne(PG_FUNCTION_ARGS)
151
152
152
153
/* We can't compare lengths in advance of downcasing ... */
153
154
154
- lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ));
155
- rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ));
155
+ lcstr = str_tolower (VARDATA_ANY (left ), VARSIZE_ANY_EXHDR (left ), PG_GET_COLLATION () );
156
+ rcstr = str_tolower (VARDATA_ANY (right ), VARSIZE_ANY_EXHDR (right ), PG_GET_COLLATION () );
156
157
157
158
/*
158
159
* Since we only care about equality or not-equality, we can avoid all the
@@ -177,7 +178,7 @@ citext_lt(PG_FUNCTION_ARGS)
177
178
text * right = PG_GETARG_TEXT_PP (1 );
178
179
bool result ;
179
180
180
- result = citextcmp (left , right ) < 0 ;
181
+ result = citextcmp (left , right , PG_GET_COLLATION () ) < 0 ;
181
182
182
183
PG_FREE_IF_COPY (left , 0 );
183
184
PG_FREE_IF_COPY (right , 1 );
@@ -194,7 +195,7 @@ citext_le(PG_FUNCTION_ARGS)
194
195
text * right = PG_GETARG_TEXT_PP (1 );
195
196
bool result ;
196
197
197
- result = citextcmp (left , right ) <= 0 ;
198
+ result = citextcmp (left , right , PG_GET_COLLATION () ) <= 0 ;
198
199
199
200
PG_FREE_IF_COPY (left , 0 );
200
201
PG_FREE_IF_COPY (right , 1 );
@@ -211,7 +212,7 @@ citext_gt(PG_FUNCTION_ARGS)
211
212
text * right = PG_GETARG_TEXT_PP (1 );
212
213
bool result ;
213
214
214
- result = citextcmp (left , right ) > 0 ;
215
+ result = citextcmp (left , right , PG_GET_COLLATION () ) > 0 ;
215
216
216
217
PG_FREE_IF_COPY (left , 0 );
217
218
PG_FREE_IF_COPY (right , 1 );
@@ -228,7 +229,7 @@ citext_ge(PG_FUNCTION_ARGS)
228
229
text * right = PG_GETARG_TEXT_PP (1 );
229
230
bool result ;
230
231
231
- result = citextcmp (left , right ) >= 0 ;
232
+ result = citextcmp (left , right , PG_GET_COLLATION () ) >= 0 ;
232
233
233
234
PG_FREE_IF_COPY (left , 0 );
234
235
PG_FREE_IF_COPY (right , 1 );
@@ -251,7 +252,7 @@ citext_smaller(PG_FUNCTION_ARGS)
251
252
text * right = PG_GETARG_TEXT_PP (1 );
252
253
text * result ;
253
254
254
- result = citextcmp (left , right ) < 0 ? left : right ;
255
+ result = citextcmp (left , right , PG_GET_COLLATION () ) < 0 ? left : right ;
255
256
PG_RETURN_TEXT_P (result );
256
257
}
257
258
@@ -264,6 +265,6 @@ citext_larger(PG_FUNCTION_ARGS)
264
265
text * right = PG_GETARG_TEXT_PP (1 );
265
266
text * result ;
266
267
267
- result = citextcmp (left , right ) > 0 ? left : right ;
268
+ result = citextcmp (left , right , PG_GET_COLLATION () ) > 0 ? left : right ;
268
269
PG_RETURN_TEXT_P (result );
269
270
}
0 commit comments