PL/pgsql function handle CUBE values
Hi, I am trying to write a PL/pgsql function that will take a CUBE
variable (which will be a 1D point) and a double precision variable.
If the input CUBE is defined as
'(x,y,z)'::cube
the function would then return a CUBE value of the form
'(x+R,y+R,z+R),(x-R,y-R,z-R)'::cube
where R is the second argument.
The problem I'm having is to actually add R to the individual
components of the CUBE variable. I can't cast CUBE to float[] and I
don't see anyway to get at the individual components of the CUBE.
Any pointers would be appreciated.
-------------------------------------------------------------------
Rajarshi Guha <rguha@indiana.edu>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
"355/113 -- Not the famous irrational number PI,
but an incredible simulation!"
Rajarshi Guha wrote:
Hi, I am trying to write a PL/pgsql function that will take a CUBE
variable (which will be a 1D point) and a double precision variable.If the input CUBE is defined as
'(x,y,z)'::cube
the function would then return a CUBE value of the form
'(x+R,y+R,z+R),(x-R,y-R,z-R)'::cube
where R is the second argument.
The problem I'm having is to actually add R to the individual components
of the CUBE variable. I can't cast CUBE to float[] and I don't see
anyway to get at the individual components of the CUBE.
I haven't tested this, but it looks like you can use cube_subset() to do
that.
From [0]http://developer.postgresql.org/pgdocs/postgres/cube.html:
cube_subset(cube, int[]) returns cube
Makes a new cube from an existing cube, using a list of dimension
indexes from an array. Can be used to find both the LL and UR
coordinates of a single dimension, e.g.
cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[2]) = '(3),(7)'. Or can be
used to drop dimensions, or reorder them as desired, e.g.
cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[3,2,1,1]) = '(5, 3, 1,
1),(8, 7, 6, 6)'.
For each dimension, select cube_subset(your_cube, ARRAY[dimension]) and
then increment or decrement by R.
Further, it looks like you're actually trying to create a function that
will do precisely what cube_enlarge() does.
Also from [0]http://developer.postgresql.org/pgdocs/postgres/cube.html:
cube_enlarge(cube c, double r, int n) returns cube
Increases the size of a cube by a specified radius in at least n
dimensions. If the radius is negative the cube is shrunk instead. This
is useful for creating bounding boxes around a point for searching for
nearby points. All defined dimensions are changed by the radius r. LL
coordinates are decreased by r and UR coordinates are increased by r.
If a LL coordinate is increased to larger than the corresponding UR
coordinate (this can only happen when r < 0) than both coordinates are
set to their average. If n is greater than the number of defined
dimensions and the cube is being increased (r >= 0) then 0 is used as
the base for the extra coordinates.
Colin
[0]: http://developer.postgresql.org/pgdocs/postgres/cube.html
On Jan 16, 2008, at 3:41 PM, Colin Wetherbee wrote:
Rajarshi Guha wrote:
Hi, I am trying to write a PL/pgsql function that will take a CUBE
variable (which will be a 1D point) and a double precision variable.
If the input CUBE is defined as
'(x,y,z)'::cube
the function would then return a CUBE value of the form
'(x+R,y+R,z+R),(x-R,y-R,z-R)'::cube
where R is the second argument.
The problem I'm having is to actually add R to the individual
components of the CUBE variable. I can't cast CUBE to float[] and
I don't see anyway to get at the individual components of the CUBE.I haven't tested this, but it looks like you can use cube_subset()
to do that.From [0]:
cube_subset(cube, int[]) returns cube
Further, it looks like you're actually trying to create a function
that will do precisely what cube_enlarge() does.
Indeed! sorry for not giving the docs a thorough a reading
Thanks for the pointer
-------------------------------------------------------------------
Rajarshi Guha <rguha@indiana.edu>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
...but there was no one in it.......
- RG