pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marcin Piotr Grondecki <ojciec@postgres.pl>
To: pgsql-sql@postgresql.org
Subject: Re: SELECT with Function
Date: Fri, 01 Oct 2004 18:46:45 +0200
Message-ID: <415D89F5.10406@postgres.pl> (raw)
In-Reply-To: <2004929105149.835585@develop>
References: <2004929105149.835585@develop>

-----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-----



view thread (3+ messages)  latest in thread

Message-ID: <415D89F5.10406@postgres.pl>
Permalink:  ../415D89F5.10406@postgres.pl/
Also on:    postgresql.org/message-id/415D89F5.10406@postgres.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ojciec@postgres.pl
  Subject: Re: SELECT with Function
  In-Reply-To: <415D89F5.10406@postgres.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox