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 07ec01c79669$25dad7a0$719086e0$@com
Whole thread Raw
In response to Re: Trouble returning a text field from an SRF  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: Trouble returning a text field from an SRF
Re: Trouble returning a text field from an SRF
List pgsql-interfaces
I created my tuple that way and set the Datum using
DirectFunctionCall1(...), but there still seems to be a limitation at 65535
chars for the data. When my string is 65535 (or shorter) I get the text
back. When it is longer I get nothing for the string, but the rest of the
tuple is intact.


My tuple descriptor:

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

Code in my pgLib extension:

//Code that handles the initial SRF stuff omitted
.
.
.
.

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"); 
values[0]= Int32GetDatum(strlen(textOut));values[1]= DirectFunctionCall1(textin,PointerGetDatum(textOut));
tuple=heap_formtuple(tupDesc, values, nulls);
result = HeapTupleGetDatum(tuple);

SRF_RETURN_NEXT(funcctx, result);
}
.

.
.
.



This function works great as long as strlen(textOut)<=65535 after that, I
get nothing for the someText value in my return type.


Any thoughts on how to get the rest of my strings when they are over 65535
bytes in length?

-----Original Message-----
From: Alvaro Herrera [mailto:alvherre@commandprompt.com]
Sent: Sunday, May 13, 2007 11:12 AM
To: Rob Tester
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] Trouble returning a text field from an SRF

Rob Tester escribió:
> I have written several postgres extensions in the past. However,currently
I
> am having difficulty with an extension returning a tuple. Basically I want
> to return a tuple containing an integer and a very large variable length
> string. I created a type on Postgres that contains two fields (int4 and
> text). Originally, I was using buildTupleFromCStrings(). My function works
> fine and everything is cool, until my string becomes large. At that
> point NULL is returned in my tuple (I believe that this is
> because Postgres is using char type conversion on the string). So, my
> question is how can I return the large string as part of my tuple? Is
there
> a Datum function that will allow me to convert a text* into a datum?  Any
> help or a push in the right direction would be appreciated.

You can use things like

DirectFunctionCall1(textin, CStringGetDatum(the-c-string))
which returns a Datum containing a Text with the C-string in it.

I would normally try to use heap_form_tuple instead of
buildTupleFromCStrings if possible, but I wouldn't think that the latter
would fail on too large texts.  It's hard to say what's failing without
actually seeing the code anyway.  Maybe the problem is failure to handle
TOAST at some level.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



pgsql-interfaces by date:

Previous
From: "Rob Tester"
Date:
Subject: Help with returning a tuple
Next
From: Tom Lane
Date:
Subject: Re: Trouble returning a text field from an SRF