Re: need of anonymous record

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: need of anonymous record
Дата
Msg-id 5365F22F.50301@2ndquadrant.com
обсуждение исходный текст
Ответ на need of anonymous record  (Peter Krauss <ppkrauss@gmail.com>)
Ответы Re: need of anonymous record
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: Possible fix for occasional failures on castoroides etc
Следующее
От: Andres Freund
Дата:
Сообщение: pg_shmem_allocations view