Re: Point and function help

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andy Lewis" <jumboc(at)comcast(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Point and function help
Date: 2003-12-25 16:43:52
Message-ID: 20664.1072370632@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Andy Lewis" <jumboc(at)comcast(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andy Lewis 2003-12-25 18:39:11 Re: Point and function help
Previous Message Tom Lane 2003-12-25 16:32:21 Re: not in vs not exists - vastly diferent performance