@@ -207,7 +207,7 @@ gettoken_txtidx(TI_IN_STATE * state)
207207Datum
208208txtidx_in (PG_FUNCTION_ARGS )
209209{
210- char * buf = ( char * ) PG_GETARG_POINTER (0 );
210+ char * buf = PG_GETARG_CSTRING (0 );
211211TI_IN_STATE state ;
212212WordEntry * arr ;
213213int4 len = 0 ,
@@ -276,7 +276,7 @@ txtidx_in(PG_FUNCTION_ARGS)
276276Datum
277277txtidxsize (PG_FUNCTION_ARGS )
278278{
279- txtidx * in = (txtidx * )DatumGetPointer ( PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ) ));
279+ txtidx * in = (txtidx * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
280280int4 ret = in -> size ;
281281
282282PG_FREE_IF_COPY (in ,0 );
@@ -286,7 +286,7 @@ txtidxsize(PG_FUNCTION_ARGS)
286286Datum
287287txtidx_out (PG_FUNCTION_ARGS )
288288{
289- txtidx * out = (txtidx * )DatumGetPointer ( PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ) ));
289+ txtidx * out = (txtidx * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
290290char * outbuf ;
291291int4 i ,
292292j ,
@@ -475,7 +475,7 @@ makevalue(PRSTEXT * prs)
475475Datum
476476txt2txtidx (PG_FUNCTION_ARGS )
477477{
478- text * in = ( text * ) DatumGetPointer ( PG_DETOAST_DATUM ( PG_GETARG_DATUM ( 0 )) );
478+ text * in = PG_GETARG_TEXT_P ( 0 );
479479PRSTEXT prs ;
480480txtidx * out = NULL ;
481481
@@ -511,7 +511,6 @@ tsearch(PG_FUNCTION_ARGS)
511511PRSTEXT prs ;
512512Datum datum = (Datum )0 ;
513513
514-
515514if (!CALLED_AS_TRIGGER (fcinfo ))
516515elog (ERROR ,"TSearch: Not fired by trigger manager" );
517516
@@ -535,7 +534,7 @@ tsearch(PG_FUNCTION_ARGS)
535534elog (ERROR ,"TSearch: format tsearch(txtidx_field, text_field1,...)" );
536535
537536numidxattr = SPI_fnumber (rel -> rd_att ,trigger -> tgargs [0 ]);
538- if (numidxattr < 0 )
537+ if (numidxattr == SPI_ERROR_NOATTRIBUTE )
539538elog (ERROR ,"TSearch: Can not find txtidx_field" );
540539
541540prs .lenwords = 32 ;
@@ -546,27 +545,35 @@ tsearch(PG_FUNCTION_ARGS)
546545/* find all words in indexable column */
547546for (i = 1 ;i < trigger -> tgnargs ;i ++ )
548547{
549- int4 numattr ;
550- text * txt_toasted ,
551- * txt ;
552- bool isnull ;
548+ int numattr ;
553549Oid oidtype ;
550+ Datum txt_datum ;
551+ bool isnull ;
552+ text * txt ;
554553
555554numattr = SPI_fnumber (rel -> rd_att ,trigger -> tgargs [i ]);
555+ if (numattr == SPI_ERROR_NOATTRIBUTE )
556+ {
557+ elog (WARNING ,"TSearch: can not find field '%s'" ,
558+ trigger -> tgargs [i ]);
559+ continue ;
560+ }
556561oidtype = SPI_gettypeid (rel -> rd_att ,numattr );
557- if (numattr < 0 || (!(oidtype == TEXTOID || oidtype == VARCHAROID )))
562+ /* We assume char() and varchar() are binary-equivalent to text */
563+ if (!(oidtype == TEXTOID ||
564+ oidtype == VARCHAROID ||
565+ oidtype == BPCHAROID ))
558566{
559- elog (WARNING ,"TSearch: can not find field '%s'" ,trigger -> tgargs [i ]);
567+ elog (WARNING ,"TSearch: '%s' is not of character type" ,
568+ trigger -> tgargs [i ]);
560569continue ;
561570}
562- txt_toasted = ( text * ) DatumGetPointer ( SPI_getbinval (rettuple ,rel -> rd_att ,numattr ,& isnull ) );
571+ txt_datum = SPI_getbinval (rettuple ,rel -> rd_att ,numattr ,& isnull );
563572if (isnull )
564573continue ;
565- txt = ( text * ) DatumGetPointer ( PG_DETOAST_DATUM ( PointerGetDatum ( txt_toasted )) );
574+ txt = DatumGetTextP ( txt_datum );
566575
567576parsetext (& prs ,VARDATA (txt ),VARSIZE (txt )- VARHDRSZ );
568- if (txt != txt_toasted )
569- pfree (txt );
570577}
571578
572579/* make txtidx value */