Re: Extending SQL in C using VARIABLE length type

From: Carsten Kropf <ckropf2(at)fh-hof(dot)de>
To: Yeb Havinga <yebhavinga(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Extending SQL in C using VARIABLE length type
Date: 2010-02-11 07:54:12
Message-ID: 1BE43A74-B178-4119-AED1-921C7025579E@fh-hof.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks a lot so far. I adopted my structures and am now storing two fields (v_len_ and dimensions) and the storage is now working properly. If I now would try to combine two of these points to a range (like cube) including an upper and a lower bound n-dimensional point structure, I don't get the point how to achieve this.
I tried around a little bit and ended up with a structure like the following:
/**
* basic structure definition for a range containing an upper and a lower point (in multiple dimensions)
*/
struct Range
{
int32 v_len_;
/**
* the upper limit in each dimension
*/
struct PointND * upper;
/**
* the lower limit in each dimension
*/
struct PointND * lower;
};
However, the problem is again, how to put this range into a table. Actually, I don't know exactly, how to do this, I tried the following:
len = VARSIZE(upper) + VARSIZE(lower) + VARHDRSZ + 2 * sizeof(struct Point *);
result = (Range *) palloc0(len);
// result->upper = upper;
// result->lower = lower;
memcpy((void *) result->upper, (void *) upper, VARSIZE(upper));
memcpy((void *) result->lower, (void *) lower, VARSIZE(lower));

// set the var size
SET_VARSIZE(result, len);
But this didn't do the trick. I did not yet find sth in the code of postgres, how to build such a combined type, unfortunately (or I did not look at the right places until now). How would one do this?

Thanks in advance
regards
Carsten Kropf
Am 10.02.2010 um 12:20 schrieb Yeb Havinga:

> Carsten Kropf wrote:
>> Oh, I see, does the VARSIZE length field have to be the total number of bytes occupied (including VARHDRSZ and the size of the structure) or only the size that is used by "my" datatype?
> Yes
>> Then it would become pretty much obvious, why this is not supposed to work.
>> I'll try it out then.
>>
> My €0,02: rename the dimensions to vl_len_ to avoid confusion and get compiler errors where you now use 'dimension'. Add a macro that converts a pointnd structure to dimension int by taking the VARSIZE_ANY_EXHDR / sizeof(float8) and use it where dimension is used now. Or if your database is small you could keep dimension in the structure.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Timo Klecker 2010-02-11 08:23:59 Re: problems maintaining boolean columns in a large table
Previous Message Torsten Zühlsdorff 2010-02-11 07:42:35 Re: PHP and PostgreSQL boolean data type