You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
matchit_cem_summary_statistics calls the functions for the treatment and each covariate that eventually run the SQL like this (i.e. for treatment = lowpressure)
CREATETABLEflights_weather_demo_matched_ate_cemAS
WITH Blocks AS
(SELECTavg(depdel15) AS avg_outcome,
subclass_id,
lowpressure,
airport
FROM flights_weather_demo_matched
GROUP BY subclass_id, lowpressure, airport), Weights AS
(SELECT cast(count(*) ASNUMERIC) /8450AS block_weight,
subclass_id
FROM flights_weather_demo_matched
GROUP BY subclass_id, airport)
SELECTBlocks.lowpressureAS treatment,
sum(avg_outcome * block_weight) AS weighted_avg_outcome,
airport
FROM Blocks, Weights
WHEREBlocks.subclass_id=Weights.subclass_idGROUP BYBlocks.lowpressure,
airport;
SELECT json_agg(
json_build_object(
'treatment', treatment,
'weighted_avg_outcome', weighted_avg_outcome,
'grouping_attribute', airport
)
)
FROM flights_weather_demo_matched_ate_cem
GROUP BY airport;
The second query returns 4 results (1 for each airport 'COS', 'MFE', 'MTJ', 'ROC')
But, since it is an aggregate group by query, when saving the results into a variable in postgresql:
CREATE OR REPLACEFUNCTIONget_json_ate(
table_name TEXT,
treatment TEXT,
grouping_attribute TEXT
) RETURNS JSONB AS $func$
DECLARE
command_string TEXT;
result_arr JSONB;
BEGIN
command_string :='SELECT json_agg(json_build_object('||'''treatment'', treatment, '||'''weighted_avg_outcome'', weighted_avg_outcome';
IF grouping_attribute IS NOT NULL THEN
command_string := command_string ||', ''grouping_attribute'', '|| quote_ident(grouping_attribute);
END IF;
command_string := command_string ||')) FROM '|| quote_ident(table_name);
IF grouping_attribute IS NOT NULL THEN
command_string := command_string ||' GROUP BY '|| quote_ident(grouping_attribute);
END IF;
RAISE NOTICE '%', command_string;
EXECUTE command_string INTO result_arr;
RETURN result_arr;
END;
$func$ LANGUAGE plpgsql;
only the first result is saved in the result_arr return value
To reproduce the issue, run scripts:
matchit_cem_summary_statistics
calls the functions for the treatment and each covariate that eventually run the SQL like this (i.e. for treatment = lowpressure)The second query returns 4 results (1 for each airport 'COS', 'MFE', 'MTJ', 'ROC')
But, since it is an aggregate group by query, when saving the results into a variable in postgresql:
only the first result is saved in the
result_arr
return valueThe text was updated successfully, but these errors were encountered: