sql - Accessing multidimensional array in the WHERE clause -
i have function pass in multidimensional array used in clause. think may have use loop not sure.
how access passed in parameter inside query?
create or replace function public.select_locations(coordinates text[][]) returns setof public.locations $body$ declare item public.locations; begin select * item public.locations latitude, longitude not in coordinates; return item; end $body$ language plpgsql volatile cost 100;
test call:
select * public.select_locations (array[array['42.449630','-123.758012'],array['42.456591','-123.844708']]);
to return every row in locations isn't in coordinates arg (if understand want), can following:
create or replace function public.select_locations(coordinates text[][]) returns setof public.locations $body$ declare item public.locations; begin item in select * public.locations array[latitude,longitude] not in (select array[coordinates[i][1], coordinates[i][2]] generate_series(array_lower(coordinates,1),array_upper(coordinates,1)) i) loop return next item; end loop; return; end $body$ language plpgsql volatile cost 100;
table locations has latitude , longitude text type columns. postgresql version 9.1.
Comments
Post a Comment