Link to home
Start Free TrialLog in
Avatar of davyberroho
davyberroho

asked on

return type of PostgreSQL function when joining 2 tables

Hello,

I'm trying to create a new postgresql function (stored procedure) and I would like to know which return type I've to use in the following query :

select *
from table1 t1,table2 t2
where t1.pid = t2.pid


I cannot use the return type table1 because the query also returns table2-values.

I've already tried this : RETURNS SETOF "anyelement". But it doesn't work.



Thanks ...


Davy (Belgium)
ASKER CERTIFIED SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also declare function to return 'setof record' type, but his has one disadvantage: when you do SELECT from this function, you have to write all fields and their types in the statement like this:

SELECT * from my_function(argument) (int field1, text field2, timestamp filed3....) (just an example, look in the manual for syntax and usage info).

Robson.