Re: Ayuda con una funcion SQL

From: "Juan Carlos Badillo Goy" <badillo(at)cav(dot)desoft(dot)cu>
To: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Ayuda con una funcion SQL
Date: 2008-06-24 12:39:19
Message-ID: 001d01c8d5f7$527273d0$c901c0c0@cav.desoft.cu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Gracias, me funcionó utilizando el UNION ALL y además de la forma que
calabazas me envió como ejemplo.

Gracias una vez más.

----- Original Message -----
From: "Calabaza" <calalinux(at)gmail(dot)com>
To: <pgsql-es-ayuda(at)postgresql(dot)org>
Sent: Monday, June 23, 2008 1:12 PM
Subject: Re: [pgsql-es-ayuda] Ayuda con una funcion SQL

2008/6/20 Juan Carlos Badillo Goy <badillo(at)cav(dot)desoft(dot)cu>:
> Ahora estoy tratando de hacer que una función me retorne lo siguiente: (la
> suma o union por asi decirlo de rs_tabla_1 y rs_tabla_2 )

Eso lo puedes hacer con una vista:

> CREATE OR REPLACE FUNCTION "public"."funct_resultante" (aid_usuario
> integer)
> RETURNS SETOF "public"."tabla_1" AS
> $body$
> declare rs_tabla_1 tabla_1%rowtype;
> declare rs_tabla_2 tabla_1%rowtype;
> begin
>
> for rs_tabla_1 in
> select * from rs_tabla_1 where propietario = aid_usuario and
> (tipo = 2 or tipo = 7)
> loop
> return next rs_tabla_1;
> end loop;
>
> for rs_tabla_2 in
> select * from rs_tabla_2 where propietario = aid_usuario and
> tipo
> = 9
> loop
> return next rs_tabla_2;
> end loop;
>
> return;
> end;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

Imagino que las columnas que devuelven ambas tablas son de igual
cantidad y del mismo tipo :

Prueba esto:

Select * from
(
select * from rs_tabla_1 where propietario = 777 and (tipo = 2 or tipo = 7)
) as a
union
(
select * from rs_tabla_2 where propietario = 777 and tipo = 9
) as b

777 = tu identificador de usuario...

Date una vuelta por:
http://www.postgresql.org/docs/8.3/interactive/sql-select.html#SQL-UNION

Un abrazo...
--
§~^Calabaza^~§ from Villa Elisa, Paraguay
----------------
A hendu hína: 1864 - 1949 RICHARD STRAUSS - op.28, Till Eulenspiegels
lustige Striche
http://foxytunes.com/artist/1864+-+1949+richard+strauss/track/op.28%2c+till+eulenspiegels+lustige+striche
--
TIP 6: ¿Has buscado en los archivos de nuestra lista de correo?
http://archives.postgresql.org/pgsql-es-ayuda

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Luis Esteban de Dios Núñez 2008-06-24 13:12:24 Re: [opensuse-es] Compilar y ejecutar cobol
Previous Message Sebastián Villalba 2008-06-24 10:03:20 Re: INCREMENTAR EL VALOR DE UNA PARTE DE UNA COLUMNA DE UNA TABALA ESPECIFICA