Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Re: Bugs: Programming Language Functions

From: "Andrew C(dot)R(dot) Martin" <a(dot)c(dot)r(dot)martin(at)reading(dot)ac(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: interfaces(at)postgreSQL(dot)org, docs(at)postgreSQL(dot)org, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: Bugs: Programming Language Functions
Date: 2000-04-11 17:04:17
Message-ID: 00041118092100.28482@sapc13.rdg.ac.uk (view raw or flat)
Thread:
Lists: pgsql-docspgsql-interfaces
On Tue, 11 Apr 2000, Tom Lane wrote:
> "Andrew C.R. Martin" <a(dot)c(dot)r(dot)martin(at)reading(dot)ac(dot)uk> writes:
> > My own particular problem simply pulls out an integer and a (text *)
> > from a varchar. It then goes away and does some calculations based on
> > these values and another external file (in fact it does a system() to
> > run an external program which does these calculations). It then build
> > a 'text' structure containing the result.
> 
> Hm.  I'm not too clear on why that would need to worry about either
> TupleTableSlot or GetAttributeByName ... shouldn't it be a simple
> function consuming a text Datum and producing another?

Errrmmm, just following the instructions in the docs:

Programmer's Manual, Chapter 4. Extensing SQL: Functins (page x414.htm), under
the C examples.

My function looks something like:


text *mppfunc(TUPLE tuple)
{
   text *attrib;
   int  resnum;
   bool isnull;
   char my_result[400];

   if(((attrib = (text *)GetAttributeByName(tuple, "substitution", &isnull))
       ==NULL) || isnull)
      return(pg_text("Invalid1"));
   strncpy(newres, VARDATA(attrib), 40);

   resnum = (int)GetAttributeByName(tuple, "codon", &isnull);
   if(isnull)
      return(pg_text("Invalid3"));

   /* Do some stuff here putting a result string in my_result */
   return(pg_text(my_result));
   
}

pg_text() is a little function to put a string into a PostgreSQL text data type.

Are you suggesting there is now an undocumented(?) easier way of doing this???

Best wishes,

Andrew

--
Dr. Andrew C.R. Martin          EMail:  a(dot)c(dot)r(dot)martin(at)reading(dot)ac(dot)uk  (work)
Lecturer in Bioinformatics              andrew(at)stagleys(dot)demon(dot)co(dot)uk (home)
University of Reading
Tel.: +44 (0)118 987 5123x7022  Fax:    +44 (0)118 931 0180

In response to

Responses

pgsql-docs by date

Next:From: Tom LaneDate: 2000-04-11 17:33:41
Subject: Re: [HACKERS] Re: Bugs: Programming Language Functions
Previous:From: Tom LaneDate: 2000-04-11 16:05:39
Subject: Re: Bugs: Programming Language Functions

pgsql-interfaces by date

Next:From: Tom LaneDate: 2000-04-11 17:33:41
Subject: Re: [HACKERS] Re: Bugs: Programming Language Functions
Previous:From: Tom LaneDate: 2000-04-11 16:05:39
Subject: Re: Bugs: Programming Language Functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group