Ayuda con función retornando registros

From: Dario Andres Almonte Alonzo <triby25(at)gmail(dot)com>
To: pgsql-es-ayuda <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Ayuda con función retornando registros
Date: 2013-09-05 15:19:21
Message-ID: CAM+Jddz=TBD-HE+uO5+=d5oqkyu+GO=4QPn3EBkrZOxfHZ-RSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

buen día lista

estoy migrando una base de datos de sql server 2005 a postgres 9.2.4,ya he
pasando las funciones que retornan valores escalares sin ningún problema.

ahora estoy empezando a migrar las funciones que retornan conjuntos de
registros y me he encontrado con un problema, me dice que debo definir cada
columna que voy a retornar.

esta es la primera función que intente migrar:

CREATE OR REPLACE FUNCTION act_depre_cuentas(codcia character varying(2))
RETURNS setof record AS
$BODY$
begin

return query SELECT codcia_hed,substring(referen1_hed from 11 for 6) as
codart_act, cnttran.idTran_hed, cnttran.modulo_hed, cnttran.codent_hed,
cnttran.referen1_hed,
cnttran.fecha_hed, cnttran.concep_hed, cnttran.monto_hed,
cntdeta.numcta_det,
cntdeta.centro_det, cntdeta.debito_det,
cntdeta.credito_det, cntdeta.debcre_det,
(select nomcta_cat from cntcatal where codcia_cat=codcia_hed and
numcta_cat=numcta_det) as cuenta,
(select descri_act from actmaes where codcia_act=codcia_hed and codart_act=
substring(referen1_hed from 11 for 6)) as activo,
(select descri_dep from actdepa where codcia_dep=codcia_hed and
coddep_dep=(select coddep_act from actmaes where codcia_act=codcia_hed and
codart_act= substring(referen1_hed from 11 for 6)) ) as departamento,
(select descri_tip from acttipo where codcia_tip=codcia_hed and
tipact_tip=(select tipart_act from actmaes where codcia_act=codcia_hed and
codart_act= substring(referen1_hed from 11 for 6)))as tipo,
(select coddep_act from actmaes where codcia_act=codcia_hed and codart_act=
substring(referen1_hed from 11 for 6)) as coddep_act,
(select tipart_act from actmaes where codcia_act=codcia_hed and codart_act=
substring(referen1_hed from 11 for 6)) as tipart_act
FROM cntdeta INNER JOIN
cnttran ON cntdeta.codcia_det = cnttran.codcia_hed
AND cntdeta.idTrand_det = cnttran.idTran_hed
where modulo_hed='ACT' and codent_hed='C' and codcia_hed = codcia;

end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

cuando la creo el resultado es: Query returned successfully with no result
in 13 ms.

pero cuando la llamo:
select * from act_depre_cuentas('01');

el resultado es:
ERROR: la lista de definición de columnas es obligatoria para funciones que
retornan «record»
SQL state: 42601
Character: 15

He estado buscando en foros y me dicen que debo definir cada parámetro en
el RETURNS o crear un type personalizado con todos los registros que quiero
retornar.

Hacer esto me tomaría muchísimo tiempo ya que tengo funciones que retornan
querys con muchísimas columnas.

Mi pregunta es,¿Hay alguna forma de retornar el query sin tener que definir
todas las columnas??

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Miguel Angel Hernandez Moreno 2013-09-05 15:24:23 Re: [pgsql-es-ayuda] Ayuda con función retornando registros
Previous Message Gilberto Castillo 2013-09-05 14:03:52 Traducción documentación PostgreSQL