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)
davyberrohoAsked:
Who is Participating?
 
earth man2Commented:
create view UR_VIEW as
select *
from table1 t1,table2 t2
where t1.pid = t2.pid

create function x returns set of UR_VIEW
etc
etc
0
 
RobsonCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.