Re: anonymous composite types for Table Functions (aka SRFs)

From: nconway(at)klamath(dot)dyndns(dot)org (Neil Conway)
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: anonymous composite types for Table Functions (aka SRFs)
Date: 2002-07-29 14:57:40
Message-ID: 20020729145740.GA6685@klamath.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Sun, Jul 28, 2002 at 10:24:34PM -0700, Joe Conway wrote:
> Attached are two patches to implement and document anonymous composite
> types for Table Functions, as previously proposed on HACKERS.

Nice work!

> 1. Creates a new pg_type typtype: 'p' for pseudo type (currently either
> 'b' for base or 'c' for catalog, i.e. a class).

I think you mentioned that typtype could be renamed to typkind -- that
sounds good to me...

> When creating a function you can do:
> CREATE FUNCTION foo(text) RETURNS setof RECORD ...
>
> When using it you can do:
> SELECT * from foo(sqlstmt) AS (f1 int, f2 text, f3 timestamp)

Is there a reason why you can't specify the return type in the function
declaration? ISTM that for most functions, the 'AS' clause will be the
same for every usage of the function.

On a related note, it is possible for the table function to examine the
attributes it has been asked to return, right? Since the current patch
requires that every call specify the return type, it might be possible
to take advantage of that to provide semi-"polymorphic" behavior
(i.e. the function behaves differently depending on the type of data
the user asked for)

> SELECT * from foo(sqlstmt) AS f(f1 int, f2 text, f3 timestamp)

What does the 'f' indicate?

> SELECT * from foo(sqlstmt) f(f1 int, f2 text, f3 timestamp)

This form of the syntax seems a bit unclear, IMHO. It seems a bit
like two function calls. Can the 'AS' be made mandatory?

Cheers,

Neil

--
Neil Conway <neilconway(at)rogers(dot)com>
PGP Key ID: DB3C29FC

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-07-29 15:03:40 Re: anonymous composite types for Table Functions (aka SRFs)
Previous Message Chris Humphries 2002-07-29 14:39:58 Re: Why is MySQL more chosen over PostgreSQL?

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2002-07-29 15:03:40 Re: anonymous composite types for Table Functions (aka SRFs)
Previous Message Christopher Kings-Lynne 2002-07-29 07:14:06 Re: New contrib: pg_reset_stats()