este es el codigo que tengo, ojala me puedan ayudar
Código SQL:
Ver original
CREATE OR REPLACE FUNCTION prueba(idTaller INTEGER, Alias VARCHAR(255)) RETURNS SETOF VEHICULOS AS $$ --DECLARE BEGIN RETURN QUERY EXECUTE 'select count(VEHICULOS.id_vehiculo)as Vehiculos_taller,locales.capacidad_instalada as Capacidad_Taller from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller ='||idTaller||' and COMPANIAS.alias = upper('||Alias||') group by locales.capacidad_instalada UNION select count(VEHICULOS.id_vehiculo),locales.capacidad_instalada from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller = '||idTaller||' and COMPANIAS.alias <> upper('||Alias||') group by locales.capacidad_instalada'; END; $$ LANGUAGE plpgsql;