Skip site navigation (1) Skip section navigation (2)

Execute SQL en Function

From: ruben avila galindo <ruben2218(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Execute SQL en Function
Date: 2011-11-29 17:20:02
Message-ID: CAKavrFpO0NsUAp+RRU8hJG=5va0CZ+9BhsvtU5r3jc=SFqA9jA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-es-ayuda
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 **********

Responses

pgsql-es-ayuda by date

Next:From: Jaime CasanovaDate: 2011-11-29 17:25:44
Subject: Re: Execute SQL en Function
Previous:From: Alejandro CarrilloDate: 2011-11-28 18:21:09
Subject: Re: saludos

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group