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

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to