immutable functions

Started by Andy Chambersover 14 years ago2 messagesgeneral
Jump to latest
#1Andy Chambers
achambers@mcna.net

The documentation has this to say about immutable functions...

or otherwise use information not directly present in its argument list

If the arguments are "row variables", does this allow access to the
data in the row? For example, is it safe to make the following
function definition immutable.

CREATE OR REPLACE FUNCTION distance(geocodes, geocodes)
RETURNS double precision AS
$BODY$
select case $1.zip = $2.zip
when true then 0
else ((acos(sin(($1.lat) * (pi()/180)) *
sin(($2.lat)*(pi()/180)) + cos(($1.lat)*(pi()/180)) *
cos(($2.lat)*(pi()/180)) * cos(($1.lon - $2.lon) *
(pi()/180))))*(180/pi())* 60 * 1.1515)
end;
$BODY$
LANGUAGE sql immutable
COST 100;

Cheers,
Andy

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andy Chambers (#1)
Re: immutable functions

Andy Chambers <achambers@mcna.net> writes:

The documentation has this to say about immutable functions...

or otherwise use information not directly present in its argument list

If the arguments are "row variables", does this allow access to the
data in the row?

Sure.

regards, tom lane