
CREATE OR REPLACE FUNCTION public.search_dms_vehicles(search text)RETURNS SETOF dms_vehicles LANGUAGE plpgsql STABLE AS $FUNCTION$ BEGIN IF search='' THEN RETURN query SELECT*FROM dms_vehicles;ELSE RETURN query SELECT*FROM dms_vehicles WHERE make ILIKE'%'||search||'%' OR model ILIKE'%'||search||'%' ORDER BY make ILIKE'%'||search||'%' OR NULL,model ILIKE'%'||search||'%' OR NULL;END IF;END$FUNCTION$;