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

Re: function returning a row

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-novice(at)postgresql(dot)org
Subject: Re: function returning a row
Date: 2005-02-11 07:13:26
Message-ID: 20050211071326.GA94372@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Thu, Feb 10, 2005 at 01:16:37PM +0100, Kjetil Haaland wrote:
> 
> I have tested my function some more and found out that it is while i am trying 
> to return it crashes. If i use a standard type like float it works, but with 
> my own type alignres it doesn't. I have used this type as return value in 
> other functions before, but not in set returning functions.

I'd suggest getting a simple set-returning function working before
adding the logic in the code you posted a couple of weeks ago.  For
example, start with a function that returns a set of integers, not
the custom type.  When you get that working, modify the function
to return a set of the custom type, but don't do anything fancy --
just create an instance of the type in the simplest way possible
and stuff some test values into it.  When that works, start adding
the extra logic that you need, but do so incrementally if possible.

The idea is to start with something that you know works, then add
a little bit at a time until it's finished or it breaks.  If it
breaks, then something about the last thing you added is likely to
be the cause, so you know where to start looking.

> When returning a float value, SRF_RETURN_NEXT(funcctx, Float8GetDatum(result)) 
> is used. What am i supposed to use for my own type to get the datum value? I 
> have tried using PointerGetDatum(result) but then the function crashes.

PointerGetDatum() works for me, at least in the tests I've done
with custom types.  Do you have a core dump?  Have you used a
debugger to get a stack trace?

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-novice by date

Next:From: Peter MountDate: 2005-02-11 10:00:46
Subject: Book
Previous:From: Bruno Wolff IIIDate: 2005-02-11 04:58:25
Subject: Re: Converting interval to numeric?

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