@@ -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{
4747char * lcstr ,
4848* rcstr ;
4949int32 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
5454result = varstr_cmp (lcstr ,strlen (lcstr ),
55- rcstr ,strlen (rcstr ));
55+ rcstr ,strlen (rcstr ),
56+ collid );
5657
5758pfree (lcstr );
5859pfree (rcstr );
@@ -75,7 +76,7 @@ citext_cmp(PG_FUNCTION_ARGS)
7576text * right = PG_GETARG_TEXT_PP (1 );
7677int32 result ;
7778
78- result = citextcmp (left ,right );
79+ result = citextcmp (left ,right , PG_GET_COLLATION () );
7980
8081PG_FREE_IF_COPY (left ,0 );
8182PG_FREE_IF_COPY (right ,1 );
@@ -92,7 +93,7 @@ citext_hash(PG_FUNCTION_ARGS)
9293char * str ;
9394Datum 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 () );
9697result = hash_any ((unsignedchar * )str ,strlen (str ));
9798pfree (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)
177178text * right = PG_GETARG_TEXT_PP (1 );
178179bool result ;
179180
180- result = citextcmp (left ,right )< 0 ;
181+ result = citextcmp (left ,right , PG_GET_COLLATION () )< 0 ;
181182
182183PG_FREE_IF_COPY (left ,0 );
183184PG_FREE_IF_COPY (right ,1 );
@@ -194,7 +195,7 @@ citext_le(PG_FUNCTION_ARGS)
194195text * right = PG_GETARG_TEXT_PP (1 );
195196bool result ;
196197
197- result = citextcmp (left ,right ) <=0 ;
198+ result = citextcmp (left ,right , PG_GET_COLLATION () ) <=0 ;
198199
199200PG_FREE_IF_COPY (left ,0 );
200201PG_FREE_IF_COPY (right ,1 );
@@ -211,7 +212,7 @@ citext_gt(PG_FUNCTION_ARGS)
211212text * right = PG_GETARG_TEXT_PP (1 );
212213bool result ;
213214
214- result = citextcmp (left ,right )> 0 ;
215+ result = citextcmp (left ,right , PG_GET_COLLATION () )> 0 ;
215216
216217PG_FREE_IF_COPY (left ,0 );
217218PG_FREE_IF_COPY (right ,1 );
@@ -228,7 +229,7 @@ citext_ge(PG_FUNCTION_ARGS)
228229text * right = PG_GETARG_TEXT_PP (1 );
229230bool result ;
230231
231- result = citextcmp (left ,right ) >=0 ;
232+ result = citextcmp (left ,right , PG_GET_COLLATION () ) >=0 ;
232233
233234PG_FREE_IF_COPY (left ,0 );
234235PG_FREE_IF_COPY (right ,1 );
@@ -251,7 +252,7 @@ citext_smaller(PG_FUNCTION_ARGS)
251252text * right = PG_GETARG_TEXT_PP (1 );
252253text * result ;
253254
254- result = citextcmp (left ,right )< 0 ?left :right ;
255+ result = citextcmp (left ,right , PG_GET_COLLATION () )< 0 ?left :right ;
255256PG_RETURN_TEXT_P (result );
256257}
257258
@@ -264,6 +265,6 @@ citext_larger(PG_FUNCTION_ARGS)
264265text * right = PG_GETARG_TEXT_PP (1 );
265266text * result ;
266267
267- result = citextcmp (left ,right )> 0 ?left :right ;
268+ result = citextcmp (left ,right , PG_GET_COLLATION () )> 0 ?left :right ;
268269PG_RETURN_TEXT_P (result );
269270}