Re: function returning a row
От | Michael Fuhr |
---|---|
Тема | Re: function returning a row |
Дата | |
Msg-id | 20041118161911.GA44655@winnie.fuhr.org обсуждение исходный текст |
Ответ на | function returning a row (Kjetil Haaland <kjetil.haaland@student.uib.no>) |
Ответы |
Re: function returning a row
|
Список | 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 http://www.fuhr.org/~mfuhr/
В списке pgsql-novice по дате отправления: