How can I return a NULL value from a function?
От
Chongbing Liu
Тема
How can I return a NULL value from a function?
Дата
Msg-id
Pine.LNX.4.58.0312182240130.15450@hongkong
Список
Дерево обсуждения
How can I return a NULL value from a function? Chongbing Liu <cliu@cs.nmsu.edu>
Re: How can I return a NULL value from a function? Tom Lane <tgl@sss.pgh.pa.us>
How can I return a pointer to a use structure from a function Chongbing Liu <cliu@cs.nmsu.edu>
Re: How can I return a pointer to a use structure from a function Tom Lane <tgl@sss.pgh.pa.us>
Hello, can you please tell me how to return a NULL value
from a function? I am running postgresql 7.3.2. and the
following is my case. Thank you very much.
Chongbing
============ header file ===============
#include "postgres.h"
#include "fmgr.h"
#include
#include
#ifndef pname_h
#define pname_h 1
struct pname
{ int size; char name[1];
};
typedef struct pname pname;
pname * pname_in( char * in);
char * pname_out( pname * nm);
#endif
============ C code =============
#include "postgres.h"
#include "fmgr.h"
#include "pname.h"
#include
#include
#ifndef pname_c
#define pname_c 1
pname * pname_in(char * in) { int i; pname * n; n = (pname *) palloc(strlen(in)+VARHDRSZ); n->size=strlen(in)+VARHDRSZ; memcpy(n->name, in, strlen(in)); if(strlen(in)<4) return (NULL); return n;
}
char * pname_out(pname* nm) { char *t; if(nm==NULL) return (NULL); t = (char *) palloc(VARSIZE(nm)-VARHDRSZ+1); strcpy(t,nm->name); return t;
}
#endif
============== psql command for function installation =============
CREATE FUNCTION pname_in (opaque) RETURNS pname AS '/home/cliu/types_lib/pname.so', 'pname_in' LANGUAGE 'c';
CREATE FUNCTION pname_out(opaque) RETURNS opaque AS '/home/cliu/types_lib/pname.so','pname_out' LANGUAGE 'c';
CREATE TYPE pname ( input = pname_in, output = pname_out, internallength = VARIABLE, externallength = VARIABLE, default = " "
);
================== test cases ===============
cliu=# select pname('abcdefghijk');
NOTICE: ok2:abcdefghijk
pname
-------------abcdefghijk
(1 row)
cliu=# select pname('ab');
NOTICE: ok2:ab
server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!#
В списке pgsql-hackers по дате отправления