Convert some simple functions from plpgsql to sql

SQL is a faster language to call, and these are very simple functions.
This commit is contained in:
Paul Norman 2015-12-21 23:59:26 -08:00
parent a9f6e26fed
commit ea7c16fbaf
2 changed files with 7 additions and 26 deletions

View File

@ -8,16 +8,12 @@
-- --
CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$ CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$
BEGIN
-- this function is silly -- this function is silly
RETURN ST_SetSRID(ST_MakePoint(lng,lat),4326); SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326);
END; $$ language SQL IMMUTABLE;
$$ language plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION CDB_LatLng (lat FLOAT8, lng FLOAT8) RETURNS geometry as $$ CREATE OR REPLACE FUNCTION CDB_LatLng (lat FLOAT8, lng FLOAT8) RETURNS geometry as $$
BEGIN
-- this function is silly -- this function is silly
RETURN ST_SetSRID(ST_MakePoint(lng,lat),4326); SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326);
END; $$ language SQL IMMUTABLE;
$$ language plpgsql IMMUTABLE;

View File

@ -5,24 +5,9 @@
CREATE OR REPLACE FUNCTION CDB_XYZ_Resolution(z INTEGER) CREATE OR REPLACE FUNCTION CDB_XYZ_Resolution(z INTEGER)
RETURNS FLOAT8 RETURNS FLOAT8
AS $$ AS $$
DECLARE -- circumference divided by 256 is z0 resolution, then divide by 2^z
earth_circumference FLOAT8; SELECT 40075017 / 256 / power(2, z);
tile_size INTEGER; $$ LANGUAGE SQL IMMUTABLE STRICT;
full_resolution FLOAT8;
BEGIN
-- Earth equatorial circumference in meters (according to wikipedia)
earth_circumference := 40075017;
-- Size of each tile in pixels (1:1 aspect ratio)
tile_size := 256;
full_resolution := earth_circumference/tile_size;
RETURN full_resolution / (power(2,z));
END
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
-- } -- }
-- { -- {