Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id SAA10018 for postgres-dist; Fri, 25 Mar 1994 18:47:53 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199403260247.SAA10018@nobozo.CS.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from faerie.CS.Berkeley.EDU (faerie.CS.Berkeley.EDU [128.32.149.14]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id SAA10009 for <postgres@postgres.Berkeley.EDU>; Fri, 25 Mar 1994 18:47:41 -0800
Received: from localhost (localhost [127.0.0.1]) by faerie.CS.Berkeley.EDU (8.6.4/8.1B) with SMTP id SAA02809; Fri, 25 Mar 1994 18:47:38 -0800
Message-Id: <199403260247.SAA02809@faerie.CS.Berkeley.EDU>
X-Authentication-Warning: faerie.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
From: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
To: aataneja@cs.mtu.edu (Anurag A. Taneja)
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: "define type ..", question about .. 
Reply-To: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
In-reply-to: Your message of Fri, 25 Mar 1994 18:34:35 -0500 (EST) 
	     <9403252334.AA13094@cs.mtu.edu> 
Date: Fri, 25 Mar 94 18:47:38 -0800
X-Sender: aoki@postgres.Berkeley.EDU
Resent-To: postgres-dist@postgres.Berkeley.EDU
X-Mts: smtp
Resent-Date: Fri, 25 Mar 94 18:47:41 -0800
Resent-XMts: smtp

aataneja@cs.mtu.edu (Anurag A. Taneja) writes:
> 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;
> 		}
> * 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 .............................

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  |  aoki@postgres.Berkeley.EDU
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki
