ERROR: structure of query does not match function result type DETAIL: Returned type double precision does not match expected type integer in column 1. CONTEXT: PL/pgSQL function get_analysis1_data(date,date) line 38 at RETURN QUERY ********** Error **********"질의 구조가 함수 결과 유형과 일치하지 않습니다. 반환 된 유형 배정 밀도가 열 1의 예상 유형 정수와 일치하지 않습니다." <code>postgresql</code> 절차의 코드에 대한
: -
CREATE
OR REPLACE FUNCTION public.get_analysis1_data(IN date, IN date) RETURNS TABLE (loc_no integer, loc_d_share double precision, loc_id_share double precision, loc_id_share_per double precision, loc_a integer, loc_m integer, loc_l integer, loc_oneway integer, loc_round integer, loc_replacement integer, loc_oncall integer, loc_avg_idshare double precision, out_no integer, out_d_share double precision, out_id_share double precision, out_id_share_per double precision, out_a integer, out_m integer, out_l integer, out_oneway integer, out_round integer, out_replacement integer, out_oncall integer, out_avg_idshare double precision) AS $ BODY $
DECLARE in_from_date ALIAS FOR $1;
in_to_date ALIAS FOR $2;
loc_no integer;
loc_d_share double precision;
loc_id_share double precision;
loc_id_share_per double precision;
loc_a integer;
loc_m integer;
loc_l integer;
loc_oneway integer;
loc_round integer;
loc_replacement integer;
loc_oncall integer;
loc_avg_idshare double precision;
out_no integer;
out_d_share double precision;
out_id_share double precision;
out_id_share_per double precision;
out_a integer;
out_m integer;
out_l integer;
out_oneway integer;
out_round integer;
out_replacement integer;
out_oncall integer;
out_avg_idshare double precision;
BEGIN
RETURN Query
SELECT
((
SELECT
count(*)
FROM
bookings
WHERE
(
is_outstation = FALSE
)
and
(
reporting_date BETWEEN in_from_date AND in_to_date
)
)
UNION
(
SELECT
coalesce(round(SUM(driver_share)), 0)
FROM
bookings
WHERE
is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(SUM(id_share)), 0)
FROM
bookings
WHERE
is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round((SUM(id_share)/SUM(driver_share + id_share))*100), 0)
FROM
bookings
WHERE
is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'A'
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'M'
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'L'
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
is_round_trip = FALSE
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
is_round_trip = TRUE
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
trip_type = 'Replacement'
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
trip_type = 'OnCall'
AND is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(AVG(id_share)), 0)
FROM
bookings
WHERE
is_outstation = FALSE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(SUM(driver_share)), 0)
FROM
bookings
WHERE
is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(SUM(id_share)), 0)
FROM
bookings
WHERE
is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(((SUM(id_share)/SUM(driver_share + id_share))*100)), 0)
FROM
bookings
WHERE
is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'A'
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'M'
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
car_type = 'L'
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
is_round_trip = FALSE
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
is_round_trip = TRUE
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
trip_type = 'Replacement'
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
count(*)
FROM
bookings
WHERE
trip_type = 'OnCall'
AND is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)
UNION
(
SELECT
coalesce(round(AVG(id_share)), 0)
FROM
bookings
WHERE
is_outstation = TRUE
AND reporting_date BETWEEN in_from_date AND in_to_date)) ;
END
$ BODY $ LANGUAGE plpgsql VOLATILE COST 100 ROWS 1000;
ALTER FUNCTION public.get_analysis1_data(date, date) OWNER TO
postgres;