STored Procedures
От | Oliver Neumann |
---|---|
Тема | STored Procedures |
Дата | |
Msg-id | am4o91$2qqg$1@news.hub.org обсуждение исходный текст |
Список | pgsql-general |
Hi there, I have a problem with a stored procedure. I want to implement a search and replace function to Postgre (because it has no support for that ... only translate but this does not work on whole strings but on single characters as far as I know). So I set up a C-routine, which looks like this : -x-x- char *pgsql_strreplace(char *s, char *t, char *u) { char *p, *r = 0; if (p = strstr(s, t)) { r = malloc(strlen(s) - strlen(t) + strlen(u) + 1); strcpy(r, s); *(r + (p - s)) = 0; strcat(r, u); strcat(r, p + strlen(t)); } return r; } -x-x- This code works standalone, but not when I set it up as a stoerd procedure in Postgre. So I did a : cc -fpic -c nidagfuncs.c� cc -shared -o nidagfuncs.so nidagfuncs.o And copied the .so file to lib-dir in PostgreSql. Then I did a : -x-x- CREATE FUNCTION pgsql_strreplace(varchar, varchar, varchar) RETURNS varchar AS '/usr/local/pgsql/current/lib/nidagfuncs.so' LANGUAGE 'C' WITH (isStrict); -x-x- Query executed OK! Now I tried to use this function, but then it crashed : -x-x- Query : SELECT pgsql_strreplace(email,"web","yahoo") from users where id=1234; Result: pqReadData() -- backend closed the channel unexpectedly. This probably means the backend terminated abnormally before or while processing the request. connection to server was lost -x-x- Any ideas why this code does not work ... i'm stuck! Thanks in advance... Oliver Neumann
В списке pgsql-general по дате отправления: