Extending SQL in C using VARIABLE length type

From: Carsten Kropf <ckropf2(at)fh-hof(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Extending SQL in C using VARIABLE length type
Date: 2010-02-10 08:32:58
Message-ID: 1ACEEE57-2B95-4592-A9E0-413FA1FA3DFC@fh-hof.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello everybody,
I am quite a novice in using the extension features of the PostgreSQL database. Actually, I have to do this for work at the university. At the moment, I am trying around a little bit with creating my own types using shared objects, written in C. The usage of static types with fixed length was actually no problem for me, so I proceeded to variable length types.
I created an n-dimensional point structure called "PointND" that contains a field of float8 values of dynamic length. I also put in a int4/int32 field for the length specification, as required by the documentation. So the structure looks like the following:
struct PointND
{
int32 dimensions;
float8 coordinates[1];
};
I hope, that at least this layout is as it is required. Together with this type, I also provide the required in and out functions to convert the structure to the internal/external representation properly.
The in/out functions work properly when giving the following statement (I also tried it using a debugger):
select '(4,5,6)'::pointnd;
pointnd
--------------------------------
(4.000000, 5.000000, 6.000000)
(1 row)

So it seems, that at least these functions do what they are supposed to.
The problem I have is that if I now create a table that should store entries of the type pointnd, it won't store them actually. If I do an insert like the following:
insert into test (point) values ('(5,16,6)'::pointnd);
INSERT 0 1

I get the feedback that one new row has been created. Actually this row has been created and the in function is also called (I also checked this using the debugger). Now, I would have expected something like the following, when querying the table:
select * from test;
point
--------------------------------
(5.000000, 16.000000, 6.000000)

But, actually I get the following:
select * from test;
point
--------------------------------
(0.000000, 0.000000, 0.000000)

The SQL-Script used to create the type can be seen here:
CREATE TYPE pointnd(
INTERNALLENGTH = VARIABLE,
ALIGNMENT=DOUBLE,
INPUT=pointnd_in,
OUTPUT=pointnd_out,
RECEIVE=pointnd_recv,
SEND=pointnd_send,
STORAGE=PLAIN
);

I played around with the parameters a little bit, but still don't know where this behaviour comes from. Actually, I was thinking that I conform to the requirements given by Postgres after having read the documentation. Storage type set to another method (like MAIN) will result in a segmentation fault, though.
I would be very glad, if somebody could provide me some help to this issue because I could proceed with my "actual" work, after that.
Thank you in advance

Best regards

Carsten Kropf

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Otandeka Simon Peter 2010-02-10 08:34:01 Re: xpath
Previous Message Davor J. 2010-02-10 08:15:20 Re: R: One column to multiple columns based on constraints?