Re: Persistence problem - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Persistence problem
Date
Msg-id 20100513104209.GB4554@svana.org
Whole thread Raw
In response to Re: Persistence problem  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Responses Re: Persistence problem  ("I. B." <i.bre@live.com>)
List pgsql-general
On Thu, May 13, 2010 at 12:04:56PM +0200, I. B. wrote:
>
>
> I'll try to explain with as less code as possible.
> One of the types I wanted to create is called mpoint. This is a part of code:

<snip>

> typedef struct {
>     int4 length;
>     int noOfUnits;
>     void *units; // this is later casted to uPoint *
> } mapping_t;
>

This is not the correct way to handle varlena types. You can create the
datum that way, but if PostgreSQL decides to compress it (as it may
when writing to disk) you won't be able to read it back. Notably, the
"length" part of a varlena type is not always 4 bytes.

Make sure you have fully understood this page:
http://www.postgresql.org/docs/8.4/static/xfunc-c.html
it has a number of examples dealing with variable length types. You
MUST use the VARDATA/VARATT/etc macros to construct and read your data.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patriotism is when love of your own people comes first; nationalism,
> when hate for people other than your own comes first.
>                                       - Charles de Gaulle

Attachment

pgsql-general by date:

Previous
From: Ivan Voras
Date:
Subject: Re: Authentication method for web app
Next
From: Thom Brown
Date:
Subject: Re: pg_dumpall custom format?