Re: 3d Vector Types and operators - Mailing list pgsql-general

From Sam Mason
Subject Re: 3d Vector Types and operators
Date
Msg-id 20091014171430.GS5407@samason.me.uk
Whole thread Raw
In response to 3d Vector Types and operators  (Andrew Bailey <hazlorealidad@gmail.com>)
List pgsql-general
On Wed, Oct 14, 2009 at 12:04:26PM -0500, Andrew Bailey wrote:
> I cant find in the documentation support for a 3 dimensional vector,
> I have only seen the array type, I am interested in doing vector dot
> products and vector cross products, also summing vectors and
> multiplying by a scalar quantity

If you did do this, I'd be tempted to use something like:

  create type point3d AS (
    x float8, y float8, z float8
  );

and then write your functions using this.  The length of an array isn't
part of its type and so PG wouldn't be able to stop you from writing:

  select array[1,2,3] + array[2,3,4,5,6];

if you provided the appropriate operators.  If you use a fixed sized
tuple, as above, you'd get errors if you tried to use points of the
wrong dimensionality.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Josip
Date:
Subject: How ad an increasing index to a query result?
Next
From: Andrew Bailey
Date:
Subject: Re: How ad an increasing index to a query result?