return type of PostgreSQL function when joining 2 tables

Posted on 2005-04-17
Last Modified: 2008-03-04

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 =

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)
Question by:davyberroho
    LVL 22

    Accepted Solution

    create view UR_VIEW as
    select *
    from table1 t1,table2 t2
    where =

    create function x returns set of UR_VIEW
    LVL 4

    Expert Comment

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


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: ( This requires some add-o…
    Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
    Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now