Re: STored Procedures

From: "Oliver Neumann" <oliver(dot)neumann(at)newidentity(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: STored Procedures
Date: 2002-09-17 07:30:14
Message-ID: am6lm6$20po$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Joe Conway" <mail(at)joeconway(dot)com> schrieb im Newsbeitrag
news:3D86249B(dot)4070801(at)joeconway(dot)com(dot)(dot)(dot)
> > 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Page 2002-09-17 07:33:35 Re: PGXLOG variable worthwhile?
Previous Message frank_lupo 2002-09-17 07:05:41 Re: postgres crash