Search Postgresql Archives

Re: unaccent as stored procedure?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 4 Dec 2006, Stephen Woodbridge wrote:

Hi all,

I was wondering if anyone has unac.c which is the lib used in Text::Unaccent built and wrap as a plpgsql stored procedure not using plperl. Or maybe there is another general solution that I am no aware of.

I have one, don't remember whet did I get it.


Thanks,
 -Steve

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


	Regards,
		Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg@xxxxxxxxxx, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83
/*
 * pg_unac.c
 *
 * Author: Nhan NGO DINH
 * Version: 1.1
 * Description: PostgreSQL external function
 *   unaccent the given string
 *
 */

#include <stdio.h>
#include <postgres.h>
#include <string.h>
#include <fmgr.h>
#include <unac.h>

PG_FUNCTION_INFO_V1(unac);

Datum unac(PG_FUNCTION_ARGS) {

  text *str = PG_GETARG_TEXT_P(0);
  text *result;
  
  int tlen, nlen;
  char *tstr, *nstr;
  
  tlen = VARSIZE(str) - VARHDRSZ;
  tstr = (char *) palloc(tlen + 1);
  memcpy(tstr, VARDATA(str), tlen);
  tstr[tlen] = '\0';

  nstr = NULL; nlen = 0;
  unac_string("UTF-8", tstr, strlen(tstr), &nstr, &nlen);

  /* It may happen that unac_string returns NULL, because iconv
   * can't translate the input string. In this case we output
   * the string as it is. */
  if (nstr == NULL) nstr = tstr;
  
  result = (text *) palloc(strlen(nstr) + VARHDRSZ);
  memcpy(VARDATA(result), nstr, strlen(nstr));
  VARATT_SIZEP(result) = strlen(nstr) + VARHDRSZ;
  
  PG_RETURN_TEXT_P(result);
  
}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux