X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1107432A9D1 for ; Sat, 9 Oct 2004 16:08:50 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80150-10 for ; Sat, 9 Oct 2004 15:08:46 +0000 (GMT) Received: from fermio.k8.com.br (fermio.k8.com.br [200.185.109.85]) by svr1.postgresql.org (Postfix) with ESMTP id 28CF932AA61 for ; Sat, 9 Oct 2004 16:08:44 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by smtpa.k8.com.br (Postfix) with ESMTP id CE0D3A000175 for ; Sat, 9 Oct 2004 12:08:39 -0300 (BRT) Received: from smtpa.k8.com.br ([127.0.0.1]) by localhost (fermio.k8.com.br [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 04558-21-38 for ; Sat, 9 Oct 2004 12:08:39 -0300 (BRT) Received: from develop (200-102-170-207.paemt7012.dsl.brasiltelecom.net.br [200.102.170.207]) by smtpa.k8.com.br (Postfix) with ESMTP id 4F1C2A0000AA for ; Sat, 9 Oct 2004 12:08:38 -0300 (BRT) From: Paulo Nievierowski To: X-Mailer: PocoMail 3.01 (1661) - Licensed Version Date: Sat, 9 Oct 2004 12:11:37 -0300 Message-ID: <2004109121137.548743@develop> In-Reply-To: <415D89F5.10406@postgres.pl> Delivery-Date: Sat, 9 Oct 2004 12:11:37 -0000 Subject: Re: SELECT with Function Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/58 X-Sequence-Number: 19161 Dear Marcin Thanks for your reply. My created function running well as exposed by you in ttt() function and this is no problem. I need extend this query. See: TableA prod_id numeric(10) prod_name varchar(40) ... My function, as your ttt(), return 3 values and value prod_id from TableA must be parameter to function. I like obtain as result: prod_id, prod_name, v1, v2, v3 The first 2 columns is from TableA and v1,v2,v3 is from function. How create a query that return this row? Or it is impossible? I have tried with UNION and JOIN without success :-( Excuse me: you is polish? From Poland? I brazilian descendant polish. Thanks Paulo Nievierowski On Fri, 01 Oct 2004 18:46:45 +0200, Marcin Piotr Grondecki wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Paulo Nievierowski wrote: > | PS: Excuses my poor english. > Your english is excellent. MY is poor!! > > | I create plpgsql function "myfunc(integer)" thats returns of type > | record with values from table X (the function decides what record > must > | be select). The parameter is an keyprod existing in table X and in > | table A. > | > | It run well sending in psql: > | SELECT * FROM myfunc( 10006530 ) as (vret1 numeric, vret2 > numeric); > | > | The problem is: > | I need return data from table A (this have column 'keyprod'). This > | value (keyprod) must be passed as parameter to myfunc(). The > result > | must be a union of columns selected from table A and result of > | myfunc(). > | > | How to create this query? It's possible? > Yep. > Look at this: > > drop table dupa cascade; > create table dupa (a int, b int, c int); > insert into dupa (a, b, c) values (1, 2, 3); > insert into dupa (a, b, c) values (2, 3, 4); > > create or replace function ttt(int) returns record as ' > declare > ~ r record; > begin > ~ select * into r from dupa where ($1=3Da); > ~ return r; > end; > ' language 'plpgsql'; > > And then: > > ojciec=3D# select * from ttt(1) as foo(aa int, bb int, cc int); > ~ aa | bb | cc > - ----+----+---- > ~ 1 | 2 | 3