From: Céline Rivière <cr@fr.netcentrex.net>
To: pgsql-sql@postgresql.org
Subject: CREATE FUNCTION and LANGUAGE 'C'
Date: Thu, 28 Feb 2002 16:44:42 +0100
Message-ID: <0b7c01c1c06e$d687e3d0$c7a638d5@fr.netcentrex.net> (raw)
Hello,
I'm trying to call a C function (C++ in fact but I think, it's not a problem) from a
stored procedure (using CREATE FUNCTION).
-------------------------------------------------------
This is the creation of my stored procedure:
CREATE FUNCTION Get_Length(TEXT)
RETURNS INTEGER
AS
'/home/ncxusers/criviere/TOOLS/lib/tools.so', 'Get_Length'
LANGUAGE 'C';
This is the C implementation of GetLength :
#include <stdio.h>
#include "postgres.h"
#include "fmgr.h"
PG_FUNCTION_INFO_V1(file_open);
extern "C" Datum file_open (PG_FUNCTION_ARGS)
{
char *szName = PG_GETARG_CSTRING(0);
long lgLength = strlen(szName);
PG_RETURN_UINT32(lgLength);
}
This is the result of the execution :
TestVersioning=# select file_open('abcdefgh') as v_result;
v_result
----------
2
(1 row)
-------------------------------------------------------
Why does it return 2 and not 8 (length of 'abcdef') ?
Thanks for your help.
Céline
PS:
I think I have a problem with string manipulation.
Because I also have a 2nd issue when trying to return a variable of type TEXT (or VARCHAR).
The following error occurs :
pqReadData() -- backend closed the channel unexpectedly.
This probably means the backend terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: cr@fr.netcentrex.net
Subject: Re: CREATE FUNCTION and LANGUAGE 'C'
In-Reply-To: <0b7c01c1c06e$d687e3d0$c7a638d5@fr.netcentrex.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox