Re: table functions

From: Joe Conway <mail(at)joeconway(dot)com>
To: "Eric B(dot)Ridge" <ebr(at)tcdi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: table functions
Date: 2002-12-09 06:01:28
Message-ID: 3DF431B8.8060408@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Eric B.Ridge wrote:
> Let's say I've defined a table function named: myTableFunc() (written in
> C), and that I do this:
>
> select a, b, c
> from myTableFunc() as foo (a integer, b varchar(255), c text)
> where a = 2;
>
> Is it possible for me to get the FROM, WHERE, and AS ... clauses from
> within my table function code? I'd like to do this so my table function
> can be a little smarter about what it does and what it returns.

You can get the information related to the "as foo (a integer, b varchar(255),
c text)" aka column definition clause. It is passed in to the function. See
contrib/tablefunc/tablefunc.c:connectby_text(). The ReturnSetInfo structure
handed to the function includes a copy of the tupdesc formed by the parser
(expectedDesc).

This capability was added so late in the 7.3 developemnt cycle that I don't
think it is documented anywhere other than the source code and some posts Tom
Lane made to the list (although I'll have to look -- he may have snuck it in
somewhere).

As far as the FROM and WHERE clauses, I don't think there is any information
available to the function. Not sure it would be practical or even possible to
change that -- maybe someone else will comment on this.

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message suresh s 2002-12-09 06:07:52 Mr Thomas problem starting postgresql
Previous Message suresh s 2002-12-09 05:52:58 problem startting postgresql