Re: [GENERAL] Geometric, getting x and y co-ordinates GOING MAD!!!!!

From: selkovjr(at)mcs(dot)anl(dot)gov
To: Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk>, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Geometric, getting x and y co-ordinates GOING MAD!!!!!
Date: 1999-06-04 15:52:16
Message-ID: 199906041650.LAA15591@antares.mcs.anl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I have no training in C so I've reached this far by trial and error. I
> have however discovered that if write a function such as
>
> /* pants.c
> weird of what! */
> #include "postgres.h"
> #include "utils/geo_decls.h"
> double
> pants(Point *pt)
> {
> return 2.0;
> }
>
> and compile it as above and make it a function I get:
>
> brecard10=> select id,pos,pants(pos) from points;
> id|pos |pants
> --+-----------+-----
> 1|(1,2) | 1
> 2|(-1.3,4.77)| -1.3
> 3|(0,-3) | 0
> (3 rows)
>
> HELP!
> WHAT'S GOING ON!!!
> Why can't I get to pt->y?
> Why does function pants behave just like get_x (and get_y)?

If you write your function as double, you can't declare it as float in sql. What you wanted is probably this:

#include "postgres.h"
#include "utils/geo_decls.h"

float32 x(Point *pt);
float32 y(Point *pt);

float32 x(Point *pt) {
float32 result = (float32) palloc(sizeof(float32data));

*result = (float)pt->x;
return (result);
}

float32 y(Point *pt) {
float32 result = (float32) palloc(sizeof(float32data));

*result = (float)pt->y;
return (result);
}

(note that float32 is a pointer type)

Then, in sql,

CREATE FUNCTION x(point)
RETURNS float4
AS '/home/postgres/src/point_adts/point_adts.so' <- this is where the above x() and y() functions live
LANGUAGE 'c';

CREATE FUNCTION y(point)
RETURNS float4
AS '/home/postgres/src/point_adts/point_adts.so'
LANGUAGE 'c';

--Gene

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here's the complete working code:

begin 644 point_adts.tgz
M'XL(`&4!6#<``^V5\6^:0!3'_;7W5[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Z'P^%P.!P.A\/A<#@<#H?#X7#>/7\!
(A%`/L(at)`H````
`
end

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Rison 1999-06-04 16:00:18 Re: [GENERAL] Geometric, getting x and y co-ordinates GOING MAD!!!!!
Previous Message James Thompson 1999-06-04 13:49:37 Re: [GENERAL] Embedded SQL in 'C' (cursors)