Re: need of anonymous record

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Peter Krauss <ppkrauss(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: need of anonymous record
Date: 2014-05-04 07:54:23
Message-ID: 5365F22F.50301@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 05/03/2014 09:55 PM, Peter Krauss wrote:

> If "yes", the /record/ datatype is somewhat outdated?

No, it isn't.

`RETURNS TABLE` is functionally the same as `RETURNS SETOF RECORD` with
`OUT` parameters. However, `RETURNS SETOF RECORD` can return arbitrary
records of no fixed structure too, and that's something `RETURNS TABLE`
cannot do.

So there's no alternative to 'record' for things like the crosstab function.

It's also important and useful for things like loop variables in PL/PgSQL.

> The second question/discussion shows a more deeper problem, where
> perhaps the use of string index in array syntax (something like x['a'])
> would be a good syntax solution.

The title of that is completely misleading, it's nothing to do with arrays.

What you appear to want is to access arbitrary fields of a record by name.

The reason this isn't supported directly in PL/PgSQL is, AFAIK, mainly
an issue of data typing. Each field in a record may be of a different
type. So the return type would change based on the field accessed at
execution time, which isn't something PL/PgSQL or regular SQL likes very
much, as plans are formed and cached in part based on the types involved.

We could and probably should provide an operator or function to access
records of a field in their text form by name. Patches are welcome ;-)

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-05-04 11:44:17 pg_shmem_allocations view
Previous Message Andres Freund 2014-05-03 19:29:18 Re: Possible fix for occasional failures on castoroides etc