@@ -18,7 +18,7 @@ PG_MODULE_MAGIC;
1818 * ====================
1919 */
2020
21- static int32 citextcmp (text * left , text * right );
21+ static int32 citextcmp (text * left , text * right , Oid collid );
2222extern Datum citext_cmp (PG_FUNCTION_ARGS );
2323extern Datum citext_hash (PG_FUNCTION_ARGS );
2424extern Datum citext_eq (PG_FUNCTION_ARGS );
@@ -42,17 +42,18 @@ extern Datum citext_larger(PG_FUNCTION_ARGS);
4242 * Returns int32 negative, zero, or positive.
4343 */
4444static int32
45- citextcmp (text * left , text * right )
45+ citextcmp (text * left , text * right , Oid collid )
4646{
4747 char * lcstr ,
4848 * rcstr ;
4949 int32 result ;
5050
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 );
5353
5454 result = varstr_cmp (lcstr , strlen (lcstr ),
55- rcstr , strlen (rcstr ));
55+ rcstr , strlen (rcstr ),
56+ collid );
5657
5758 pfree (lcstr );
5859 pfree (rcstr );
@@ -75,7 +76,7 @@ citext_cmp(PG_FUNCTION_ARGS)
7576 text * right = PG_GETARG_TEXT_PP (1 );
7677 int32 result ;
7778
78- result = citextcmp (left , right );
79+ result = citextcmp (left , right , PG_GET_COLLATION () );
7980
8081 PG_FREE_IF_COPY (left , 0 );
8182 PG_FREE_IF_COPY (right , 1 );
@@ -92,7 +93,7 @@ citext_hash(PG_FUNCTION_ARGS)
9293 char * str ;
9394 Datum result ;
9495
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 () );
9697 result = hash_any ((unsigned char * ) str , strlen (str ));
9798 pfree (str );
9899
@@ -121,8 +122,8 @@ citext_eq(PG_FUNCTION_ARGS)
121122
122123 /* We can't compare lengths in advance of downcasing ... */
123124
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 () );
126127
127128 /*
128129 * Since we only care about equality or not-equality, we can avoid all the
@@ -151,8 +152,8 @@ citext_ne(PG_FUNCTION_ARGS)
151152
152153 /* We can't compare lengths in advance of downcasing ... */
153154
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 () );
156157
157158 /*
158159 * Since we only care about equality or not-equality, we can avoid all the
@@ -177,7 +178,7 @@ citext_lt(PG_FUNCTION_ARGS)
177178 text * right = PG_GETARG_TEXT_PP (1 );
178179 bool result ;
179180
180- result = citextcmp (left , right ) < 0 ;
181+ result = citextcmp (left , right , PG_GET_COLLATION () ) < 0 ;
181182
182183 PG_FREE_IF_COPY (left , 0 );
183184 PG_FREE_IF_COPY (right , 1 );
@@ -194,7 +195,7 @@ citext_le(PG_FUNCTION_ARGS)
194195 text * right = PG_GETARG_TEXT_PP (1 );
195196 bool result ;
196197
197- result = citextcmp (left , right ) <= 0 ;
198+ result = citextcmp (left , right , PG_GET_COLLATION () ) <= 0 ;
198199
199200 PG_FREE_IF_COPY (left , 0 );
200201 PG_FREE_IF_COPY (right , 1 );
@@ -211,7 +212,7 @@ citext_gt(PG_FUNCTION_ARGS)
211212 text * right = PG_GETARG_TEXT_PP (1 );
212213 bool result ;
213214
214- result = citextcmp (left , right ) > 0 ;
215+ result = citextcmp (left , right , PG_GET_COLLATION () ) > 0 ;
215216
216217 PG_FREE_IF_COPY (left , 0 );
217218 PG_FREE_IF_COPY (right , 1 );
@@ -228,7 +229,7 @@ citext_ge(PG_FUNCTION_ARGS)
228229 text * right = PG_GETARG_TEXT_PP (1 );
229230 bool result ;
230231
231- result = citextcmp (left , right ) >= 0 ;
232+ result = citextcmp (left , right , PG_GET_COLLATION () ) >= 0 ;
232233
233234 PG_FREE_IF_COPY (left , 0 );
234235 PG_FREE_IF_COPY (right , 1 );
@@ -251,7 +252,7 @@ citext_smaller(PG_FUNCTION_ARGS)
251252 text * right = PG_GETARG_TEXT_PP (1 );
252253 text * result ;
253254
254- result = citextcmp (left , right ) < 0 ? left : right ;
255+ result = citextcmp (left , right , PG_GET_COLLATION () ) < 0 ? left : right ;
255256 PG_RETURN_TEXT_P (result );
256257}
257258
@@ -264,6 +265,6 @@ citext_larger(PG_FUNCTION_ARGS)
264265 text * right = PG_GETARG_TEXT_PP (1 );
265266 text * result ;
266267
267- result = citextcmp (left , right ) > 0 ? left : right ;
268+ result = citextcmp (left , right , PG_GET_COLLATION () ) > 0 ? left : right ;
268269 PG_RETURN_TEXT_P (result );
269270}
0 commit comments