Hola queria saber si se puede ejecutar una sentencia SQL y agregar mas
clausulas de acuerdo a condiciones algo asi.

sch_rpt.dtp_ventas es mi Type


CREATE OR REPLACE FUNCTION sch_rpt.fun_prueba(arg_id_sucursal integer,
arg_id_producto integer,arg_fecha text)
  RETURNS SETOF sch_rpt.dtp_ventas AS
$BODY$
DECLARE vl_productos sch_rpt.dtp_ventas;
DECLARE SSQL TEXT;

Begin
SSQL =
'select * from producto '

        IF (arg_id_producto IS NOT NULL) THEN
SSQL=SSQL || ' AND id_producto = ' || arg_id_producto;
END IF;
        SSQL = SSQL || 'and fecha >='|| to_timestamp(arg_fecha,'YYYY-MM-DD
HH:MM:SS') ||'and fecha <='|| to_timestamp(arg_fecha,'YYYY-MM-DD
HH:MM:SS') + Interval|| ' '15 minute' ORDER BY cod_maq_casino';
        FOR vl_productos IN EXECUTE SSQL LOOP
        END LOOP;
RETURN;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

me arroja este error

ERROR:  conflicting values for "MM" field in formatting string

DETAIL:  This value contradicts a previous setting for the same field type.

CONTEXT:  PL/pgSQL function "fun_get_contadores_hora_corte_prueba" line 31
at assignment


********** Error **********

Responder a