Re: STored Procedures - Mailing list pgsql-general

From Oliver Neumann
Subject Re: STored Procedures
Date
Msg-id am6lm6$20po$1@news.hub.org
Whole thread Raw
In response to Re: STored Procedures  (Joe Conway <mail@joeconway.com>)
List pgsql-general
"Joe Conway" <mail@joeconway.com> schrieb im Newsbeitrag
news:3D86249B.4070801@joeconway.com...
> > This code works standalone, but not when I set it up as a
> > stoerd procedure in Postgre.
>
> You need to write this in an fmgr compatable way. See the docs:
>    http://www.postgresql.org/idocs/index.php?xfunc-c.html
> You want to use the "Version-1" calling conventions. You might also want
(or
> need) to consider what happens if you're using this function in a
multibyte
> database.

Thanks for the tipp ... so I rewrote this function as V1 .. now it looks
like this, but
the error stays the same. Can you help me?

-x-x-
#include "postgres.h"
#include "fmgr.h"

PG_FUNCTION_INFO_V1(pgsql_strreplace);

Datum
pgsql_strreplace(PG_FUNCTION_ARGS)
{
    char *s = (char *) PG_GETARG_VARCHAR_P(0);
    char *t = (char *) PG_GETARG_VARCHAR_P(1);
    char *u = (char *) PG_GETARG_VARCHAR_P(2);

    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));
    }

    PG_RETURN_VARCHAR_P(r);
}
-x-x-

Error-Message :

-x-x-
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-

> Note that 7.3 (which is currently in beta) has a replace function:

That's impossible ... we have to use PostgreSQL 7.2.1 ... unfortunately ...

Thanks
Oliver



pgsql-general by date:

Previous
From: "frank_lupo"
Date:
Subject: Re: postgres crash
Next
From: "Andy Samuel"
Date:
Subject: Re: [pgsql-advocacy] An opportunity to prove PostgreSQL and our requirement of Case Study info