Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-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

pgsql-hackers by date

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

pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group