Re: Proposal: casts row to array and array to row

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal: casts row to array and array to row
Date: 2011-10-11 12:45:14
Message-ID: CAFj8pRBjq_4UcwadfJgDq5G4k4G_U_GTQQFDPao2qHK7wdrymw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2011/10/11 Robert Haas <robertmhaas(at)gmail(dot)com>:
> On Tue, Oct 11, 2011 at 4:40 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> Hello
>>
>> A current limits of dynamic work with row types in PL/pgSQL can be
>> decreased with a possible casts between rows and arrays. Now we have a
>> lot of tools for arrays, and these tools should be used for rows too.
>>
>> postgres=# \d mypoint
>> Composite type "public.mypoint"
>>  Column │  Type   │ Modifiers
>> ────────┼─────────┼───────────
>>  a      │ integer │
>>  b      │ integer │
>>
>> postgres=# select cast(rmypoint '(10,20) as int[]);
>>   array
>> ────────────
>>  {10,20}
>> (1 row)
>>
>> postgres=# select cast(ARRAY[10,20] AS mypoint);
>>  mypoint
>> ─────────
>>  (10,20)
>> (1 row)
>>
>> What do you think about this idea?
>
> Well, a ROW can contain values of different types; an ARRAY can't.

yes, I know - but it should be problem only in few cases - when is not
possible to cast a row field to array field.

This is based on user knowledge - it has to choose a adequate array type

sometimes he can use a numeric or int array, sometimes he have to
select text array. Target type is selected by user, and cast fail when
conversion is not possible.

Pavel

>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-10-11 12:48:11 Re: Proposal: casts row to array and array to row
Previous Message David Fetter 2011-10-11 12:43:07 Re: Range Types - typo + NULL string constructor