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: pgsql-novice(at)postgresql(dot)org
Subject: Re: function returning a row
Date: 2004-11-18 16:19:11
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Thu, Nov 18, 2004 at 02:54:31PM +0100, Kjetil Haaland wrote:
> I have made my own type alignres that holds a string and an integer. I have 
> created the type in postgres and tried to insert into it and it works. I also 
> have a function that returns a row (or composite type). I have used 
> tupdesc = RelationNameGetTupleDesc("alignres"); 
> to set it to return my own type.  When i try to use the function in postgres 
> it says
> ERROR:  relation "alignres" does not exist

The type you created isn't a composite -- it's a base (scalar) type.
Do you want to return a row with a field that has your type, or do
you just want to return a single value of your type?

> If i try to let the function use a type that is only created in postgres (not 
> c code) then it works. 

I assume you mean it works for a composite type like this:

CREATE TYPE foo AS (val INTEGER, fstring TEXT);

As the CREATE TYPE documentation says, this is essentially the same
as the row type of a table.  But your type is a scalar, not a composite,
so RelationNameGetTupleDesc() doesn't work.

> Is it possible to use my own type to be returned?

Yes, and you've already written a function that does: alignres_in().
Its CREATE FUNCTION statement says "RETURNS alignres", doesn't it?
If you want the new function to return a single value of your type,
then do what alignres_in() does.

Michael Fuhr

In response to


pgsql-novice by date

Next:From: Bruno Wolff IIIDate: 2004-11-18 17:31:54
Subject: Re: upgrade from postgres 7.3.2
Previous:From: Kjetil HaalandDate: 2004-11-18 13:54:31
Subject: function returning a row

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