Re: Trouble returning a text field from an SRF - Mailing list pgsql-interfaces

From Rob Tester
Subject Re: Trouble returning a text field from an SRF
Date
Msg-id 07ee01c79680$8b674650$a235d2f0$@com
Whole thread Raw
In response to Re: Trouble returning a text field from an SRF  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-interfaces
Thanks for the tip, I will correct that if I ever get the long strings to be
returned.

I use BlessTupleDesc() in the first SRF call as the following:

BlessTupleDesc(RelationNameGetTupleDesc("testText"));

As per a previous email testText is a Type that I created on the server
using:


CREATE TYPE testText AS  (alevel integer,   someText text);



-----Original Message-----
From: Gregory Stark [mailto:stark@enterprisedb.com] 
Sent: Monday, May 14, 2007 4:30 PM
To: Rob Tester
Cc: 'Alvaro Herrera'; pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] Trouble returning a text field from an SRF

"Rob Tester" <robtester@gmail.com> writes:

> textOut=palloc(MIN_SIZE*count);
> if (textOut){
>     strcpy(textOut,"TEST=>");
>     for(pointCnt=0;pointCnt<count;pointCnt++){
>         if (pointCnt!=0){
>             strcat(wktStr,",");
>         }
>         sprintf(buffer,"%4.8lf %4.8lf",0.0,0.0);
>         strcat(textOut,buffer);
>     }
>     strcat(wktStr,"==>END");

Fwiw, this isn't the cause of your 64k limit but if you're processing
thousands of data points this way you might consider rewriting it without
the
strcats. As is it's a O(n^2) algorithm. Each time through the loop it'll
have
to scan the entire string it already has built up (twice even). Instead just
keep a pointer to the end of the string and add your stuff there. You can
use
strcpy and pass it the pointer to the end, or just call sprintf directly on
that pointer.

>     tuple=heap_formtuple(tupDesc, values, nulls);

I'm curious about where you got the tupDesc and what it contains.



--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com



pgsql-interfaces by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Trouble returning a text field from an SRF
Next
From: Tom Lane
Date:
Subject: Re: Trouble returning a text field from an SRF