Code: Select all
CREATE OR REPLACE FUNCTION sales_stats(IN start_date timestamp with time zone, IN end_date timestamp with time zone, OUT sale_date timestamp with time zone, OUT amount numeric, OUT quantity integer, OUT orders integer)
RETURNS SETOF record AS
$BODY$
SELECT date_trunc('day', placed_at), SUM(soi.value), CAST(SUM(soi.quantity) AS int), CAST(COUNT(DISTINCT so.shop_order_id) AS int)
FROM shop_order so JOIN shop_order_item soi ON so.shop_order_id = soi.shop_order_id WHERE so.order_status != 'X' AND so.placed_at >= $1 AND so.placed_at <= $2 GROUP BY date_trunc('day', placed_at)
ORDER BY date_trunc('day', placed_at);
$BODY$
LANGUAGE 'sql'
Code: Select all
dotConnect for PostgreSQL: - Prepare: SELECT * FROM sales_stats($1, $2)
dotConnect for PostgreSQL: - Execute: SELECT * FROM sales_stats($1, $2)
dotConnect for PostgreSQL: - Prepare: FETCH ALL FROM "03/10/2009 00:00:00.000000+03 AD"
dotConnect for PostgreSQL: - cursor "03/10/2009 00:00:00.000000+03 AD" does not exist
The function works as expected when executed manually in pg console.
Any solutions for this?