Re: user defined type

From: Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: user defined type
Date: 2004-11-09 12:38:29
Message-ID: 200411091338.29654.kjetil.haaland@student.uib.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Monday 08 November 2004 22:24, Michael Fuhr wrote:
> On Mon, Nov 08, 2004 at 01:26:55PM +0100, Kjetil Haaland wrote:
> > typedef struct alignres {
> > int value;
> > char *fstring;
> > }alignres;
>
> If you want to store character data, I think the characters must
> be stored in the structure itself; I don't think using a pointer
> will work (somebody please correct me if I'm mistaken). So instead
> of "char *fstring" you'll need "char fstring[x]", where "x" is the
> maximum size of the character data. You could also use "char fstring[1]"
> and allocate the alignres structure to be as big as necessary; if
> you do that then you might want to review the paragraph regarding
> TOAST-able types near the end of the "User-Defined Types" section
> of the documentation.
>
> http://www.postgresql.org/docs/7.4/static/xtypes.html
>
> Make sure your CREATE TYPE statement has "internallength" set
> correctly: either to the fixed size of the structure (including
> character data) or to "variable". If you use "variable" then make
> sure you add the required length field to the beginning of the
> structure. See the CREATE TYPE documentation for more info.

Thanks for the answer. There are some stuff i don't understand. I want to use
the fstring[1] way, because i don't know how large my string will be. You say
that i can allocate the hole structure, where should i do this? in the
in-data-function? It also says in the documentation that if I use the random
for internallength when i create my type I have to set the length in the
structure. Is this set in the declaration of the structure or in some of the
methods?

-Kjetil

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2004-11-09 14:01:40 Re: Getting a trigger to call a function...
Previous Message graeme 2004-11-09 09:36:01 Getting a trigger to call a function...