Subject: "define type ..", question about ..

From: [email-masked] (Anurag A. Taneja)
Date: Fri, 25 Mar 1994 18:34:35 -0500 (EST)

Hi folks,

I am doing my thesis on nested databases ..

I was wondering if I can emulate nested databases on top of postgres..

To make the question simple .. Can I (or can i not), create
a new base data type say square, which consists of another defined
data type (say array of circle (from user manual)), and do something like:

typedef struct {
	circle c1[];
	double length;
	double width;
		}
==================
GO
* create test(sq=square) \g

* append test(sq="(2.0, 3.0, (1.0, 2.0, 4.0), (2.0, 2.2, 8.0))"::square) \g
                   |    |     |*circle params*| |*another circle*|
                   square params .............................

==================

If yes, how do I convert my circle.o (or circle.c) to be in the 
library of postgres (just like you POINT in utils/geo-decls.h) ..

thanks a zillion ...
hope u can help me on this ***pleeeasseee**!!!!
Bruce !

---

From: [email-masked] (Paul M. Aoki)
Date: Fri, 25 Mar 94 18:47:38 -0800

>                    square params .............................

perhaps this is not clear from the manual, but base types are
implemented using c structures and functions.  if you know c
well enough to write the 50-odd lines of code needed to parse
your external representation (the stuff between the quotes) and 
turn it into your typedef (and vice versa), life is good.

life is not good if you want to be able to reach into a base 
type *using the array notation in the query language*.  you 
have to write a function to do reach into base types.  think 
of base types are opaque from the query language.  there used 
to be a documented interface to build your own arrays but
that no longer exists in 4.2 (arrays are still there and the 
implementation now supports multidimensional arrays and such
but the documentation on the internal format was never written).

an aside:
notice that you have a variable-length type, so you will have to
implement it using a four-byte length header as mentioned in the 
manual.  also mentioned in the manual is the fact that you can't 
have pointers in the internal representation of your base type.
hence, such a type would be more like

	typedef struct {
		int size;	/* size in bytes */
		int n_circles;	/* number of CIRCLES in circles */
		double length;
		double width;
		CIRCLE circles[1]; /* variable-length array */
	} SQUARE;

instructions on writing code for use in the backend and building
shared libraries for dynamic loading are in the user manual.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki