pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with function...
3+ messages / 3 participants
[nested] [flat]
* Problem with function...
@ 2000-12-18 22:16 jkakar@expressus.com
0 siblings, 2 replies; 3+ messages in thread
From: jkakar@expressus.com @ 2000-12-18 22:16 UTC (permalink / raw)
To: pgsql-sql
Hi,
I hope my question is appropriate for this list. I'm trying to create
a function that calculates the distance between a pair of
latitude/longitude points. This is what I have:
/* latlon_distance.pgsql
* by Jamu Kakar <jkakar@expressus.com>, Dec 18, 2000.
*
* Calculates the distance between 2 lat/lon pairs. Syntax:
* distance (lat1, lon1, lat2, lon2) where parameters are in decimal degrees.
*/
CREATE FUNCTION distance (float8, float8, float8, float8) RETURNS float8 AS '
DECLARE
radius constant float8 := 6378;
distance float8;
lat1 ALIAS FOR $1;
lon1 ALIAS FOR $2;
lat2 ALIAS FOR $3;
lon2 ALIAS FOR $4;
BEGIN
distance := radius * acos ((sin (radians (lat1)) * sin (radians (lat2))) +
(cos (radians (lat1)) * cos (radians (lat2)) *
cos (radians (lon1) - radians (lon2))));
RETURN ''distance'';
END;
' LANGUAGE 'plpgsql';
When I try a:
select distance(49.0,-122.0,50.0,-123.0) as distance;
I get:
ERROR: Bad float8 input format 'distance'
I've tried a variety of ways of specifying the values and I've hunted
through the mailing lists but haven't turned up anything useful. Any
help would be appreciated.
Thanks,
Jamu.
--
Jamu Kakar (Developer) Expressus Design Studio, Inc.
jkakar@expressus.com 708-1641 Lonsdale Avenue
V: (604) 988-6999 North Vancouver, BC, V7M 2J5
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with function...
@ 2000-12-18 22:30 Michael Fork <mfork@toledolink.com>
parent: jkakar@expressus.com
1 sibling, 0 replies; 3+ messages in thread
From: Michael Fork @ 2000-12-18 22:30 UTC (permalink / raw)
To: jkakar@expressus.com; +Cc: pgsql-sql
I don't think you return should have '' around them, i.e.
RETURN distance;
Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio
On Mon, 18 Dec 2000 jkakar@expressus.com wrote:
> Hi,
>
> I hope my question is appropriate for this list. I'm trying to create
> a function that calculates the distance between a pair of
> latitude/longitude points. This is what I have:
>
> /* latlon_distance.pgsql
> * by Jamu Kakar <jkakar@expressus.com>, Dec 18, 2000.
> *
> * Calculates the distance between 2 lat/lon pairs. Syntax:
> * distance (lat1, lon1, lat2, lon2) where parameters are in decimal degrees.
> */
>
> CREATE FUNCTION distance (float8, float8, float8, float8) RETURNS float8 AS '
> DECLARE
> radius constant float8 := 6378;
> distance float8;
> lat1 ALIAS FOR $1;
> lon1 ALIAS FOR $2;
> lat2 ALIAS FOR $3;
> lon2 ALIAS FOR $4;
> BEGIN
> distance := radius * acos ((sin (radians (lat1)) * sin (radians (lat2))) +
> (cos (radians (lat1)) * cos (radians (lat2)) *
> cos (radians (lon1) - radians (lon2))));
> RETURN ''distance'';
> END;
> ' LANGUAGE 'plpgsql';
>
> When I try a:
>
> select distance(49.0,-122.0,50.0,-123.0) as distance;
>
> I get:
>
> ERROR: Bad float8 input format 'distance'
>
> I've tried a variety of ways of specifying the values and I've hunted
> through the mailing lists but haven't turned up anything useful. Any
> help would be appreciated.
>
> Thanks,
> Jamu.
>
> --
> Jamu Kakar (Developer) Expressus Design Studio, Inc.
> jkakar@expressus.com 708-1641 Lonsdale Avenue
> V: (604) 988-6999 North Vancouver, BC, V7M 2J5
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with function...
@ 2000-12-19 03:21 Jie Liang <jliang@jliang.ipinc.com>
parent: jkakar@expressus.com
1 sibling, 0 replies; 3+ messages in thread
From: Jie Liang @ 2000-12-19 03:21 UTC (permalink / raw)
To: jkakar@expressus.com; +Cc: pgsql-sql
Hi, there,
modify the code as following.
Jie LIANG
Internet Products Inc.
10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873
jliang@ipinc.com
www.ipinc.com
On Mon, 18 Dec 2000 jkakar@expressus.com wrote:
> Hi,
>
> I hope my question is appropriate for this list. I'm trying to create
> a function that calculates the distance between a pair of
> latitude/longitude points. This is what I have:
>
> /* latlon_distance.pgsql
> * by Jamu Kakar <jkakar@expressus.com>, Dec 18, 2000.
> *
> * Calculates the distance between 2 lat/lon pairs. Syntax:
> * distance (lat1, lon1, lat2, lon2) where parameters are in decimal degrees.
> */
>
> CREATE FUNCTION distance (float8, float8, float8, float8) RETURNS float8 AS '
> DECLARE
> radius constant float8 := 6378;
> distance float8;
> lat1 ALIAS FOR $1;
> lon1 ALIAS FOR $2;
> lat2 ALIAS FOR $3;
> lon2 ALIAS FOR $4;
> BEGIN
> distance := radius * acos ((sin (radians (lat1)) * sin (radians (lat2))) +
> (cos (radians (lat1)) * cos (radians (lat2)) *
> cos (radians (lon1) - radians (lon2))));
> -- RETURN ''distance''; -- here means text instead of float8 which
-- you defined.
===> RETURN distance;
> END;
> ' LANGUAGE 'plpgsql';
>
> When I try a:
>
> select distance(49.0,-122.0,50.0,-123.0) as distance;
>
> I get:
>
> ERROR: Bad float8 input format 'distance'
>
> I've tried a variety of ways of specifying the values and I've hunted
> through the mailing lists but haven't turned up anything useful. Any
> help would be appreciated.
>
> Thanks,
> Jamu.
>
> --
> Jamu Kakar (Developer) Expressus Design Studio, Inc.
> jkakar@expressus.com 708-1641 Lonsdale Avenue
> V: (604) 988-6999 North Vancouver, BC, V7M 2J5
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-12-19 03:21 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-12-18 22:16 Problem with function... jkakar@expressus.com
2000-12-18 22:30 ` Michael Fork <mfork@toledolink.com>
2000-12-19 03:21 ` Jie Liang <jliang@jliang.ipinc.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox