immutable functions - Mailing list pgsql-general

From Andy Chambers
Subject immutable functions
Date
Msg-id CAAfW55ohFdSOgczfRc0Tt=ZZahkAFd0J1gSCHhMVnf64-MD6FA@mail.gmail.com
Whole thread Raw
Responses Re: immutable functions
List pgsql-general
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

pgsql-general by date:

Previous
From: Ronan Dunklau
Date:
Subject: Re: Any experiences with Foreign Data Wrappers (FDW) like mysql_fdw, odbc_fdw, www_fdw or odbc_fdw?
Next
From: Heiko Wundram
Date:
Subject: Limiting number of connections to PostgreSQL per IP (not per DB/user)?