Re: SELECT with Function

From: Marcin Piotr Grondecki <ojciec(at)postgres(dot)pl>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT with Function
Date: 2004-10-01 16:46:45
Message-ID: 415D89F5.10406@postgres.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

-----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=a);
~ return r;
end;
' language 'plpgsql';

And then:

ojciec=# select * from ttt(1) as foo(aa int, bb int, cc int);
~ aa | bb | cc
- ----+----+----
~ 1 | 2 | 3

Is this what you need?
- --
ojciec
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBXYnyCAdl/NTXOsERAs/EAKCUq26LmG9N36vW/WXGC4i92Ci4VwCdF+eS
fiiHtfCVDONxxldr4SC17TI=
=tahv
-----END PGP SIGNATURE-----

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2004-10-01 18:28:30 Re: date_trunc'd timestamp index possible?
Previous Message Jeff Boes 2004-10-01 13:28:59 Re: psql variable interpolation from command line