Received: from glass.toledolink.com (glass.toledolink.com [205.133.127.8]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBIMU4622047 for ; Mon, 18 Dec 2000 17:30:04 -0500 (EST) (envelope-from mfork@toledolink.com) Received: from localhost (mfork@localhost) by glass.toledolink.com (8.10.2/8.10.2) with ESMTP id eBIMU9109086; Mon, 18 Dec 2000 17:30:09 -0500 (EST) Date: Mon, 18 Dec 2000 17:30:09 -0500 (EST) From: Michael Fork To: jkakar@expressus.com cc: pgsql-sql@postgresql.org Subject: Re: Problem with function... In-Reply-To: <20001218141644.A4107@expressus.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200012/202 X-Sequence-Number: 536 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 , 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 >