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

Re: Trouble returning a text field from an SRF

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Rob Tester <robtester(at)gmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Trouble returning a text field from an SRF
Date: 2007-05-13 18:11:54
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
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                      
The PostgreSQL Company - Command Prompt, Inc.

In response to


pgsql-interfaces by date

Next:From: Rob TesterDate: 2007-05-14 20:47:52
Subject: Re: Trouble returning a text field from an SRF
Previous:From: Rob TesterDate: 2007-05-12 15:26:22
Subject: Trouble returning a text field from an SRF

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