STored Procedures

From: "Oliver Neumann" <oliver(dot)neumann(at)newidentity(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: STored Procedures
Date: 2002-09-16 14:02:11
Message-ID: am4o91$2qqg$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Dalitz 2002-09-16 14:15:44 Re: Table with 90 columns
Previous Message Tino Wildenhain 2002-09-16 13:34:20 problems to restore database with custom datatypes (e.g. txtidx)