Re: Point and function help - Mailing list pgsql-sql

From Tom Lane
Subject Re: Point and function help
Date
Msg-id 20664.1072370632@sss.pgh.pa.us
Whole thread Raw
In response to Point and function help  ("Andy Lewis" <jumboc@comcast.net>)
Responses Re: Point and function help
List pgsql-sql
"Andy Lewis" <jumboc@comcast.net> writes:
> CREATE OR REPLACE FUNCTION public.map_point(pg_catalog.varchar,
> pg_catalog.varchar, pg_catalog.varchar)
>   RETURNS point AS
> 'SELECT map_loc from zip_code where zip = \'$3\' and lower(state) =
> lower(\'$2\') and lower(city) = lower(\'$1\')'
>   LANGUAGE 'sql' VOLATILE;

You don't want to quote the parameter references --- what you've got
there is simple literal constants '$3' etc.  Try

CREATE OR REPLACE FUNCTION public.map_point(pg_catalog.varchar,
pg_catalog.varchar, pg_catalog.varchar) RETURNS point AS
'SELECT map_loc from zip_code where zip = $3 and lower(state) =
lower($2) and lower(city) = lower($1)' LANGUAGE 'sql' VOLATILE;

Also, I can't see any reason why this function needs to be VOLATILE;
STABLE should be enough, no?
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: not in vs not exists - vastly diferent performance
Next
From: "Andy Lewis"
Date:
Subject: Re: Point and function help