[PostgreSql]PostgreSql调⽤函数及⽤IFEXISTS判断表是否存在1.创建⼀个函数function1
-- FUNCTION: public.function1(character varying, integer)
-- DROP FUNCTION public.function1(character varying, integer);
CREATE OR REPLACE FUNCTION public.function1(
useridl character varying,
groupidl integer)
RETURNS TABLE(vehicle_id integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
BEGIN
-- Insert statements for procedure here
RETURN QUERY
select v.vehicle_id
from mst_vehicle as v
where v.deletef=0;
END;
$BODY$;
ALTER FUNCTION public.function1(character varying, integer)
OWNER TO postgres;
2.在另⼀个函数function2中调⽤function1
-- FUNCTION: public.function2(character varying,integer,timestamp without time zone)
-- DROP FUNCTION public.function2(character varying,integer,timestamp without time zone);
CREATE OR REPLACE FUNCTION public.function2(
userIDl character varying,
groupIDl integer,
minVersionl timestamp without time zone)
RETURNS TABLE(
loading_info character varying(16)
)
LANGUAGE 'plpgsql'
COST 100.0
AS $function$
BEGIN
-- Insert statements for procedure here
drop table IF p_ids;
create p_ids(vehicle_id int);
insert p_ids values(function1(userIDl,groupIDl));
RETURN QUERY
select
car.loading_info
from dy_VehicleList
drop table if exists userdrop table IF p_ids;
END;
$function$;
ALTER FUNCTION public.function2(character varying,integer,timestamp without time zone)
OWNER TO postgres;
其中⽤IF EXISTS判断表是否存在,存在则删除
DROP TABLE IF EXISTS tableName

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。