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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: casts row to array and array to row
Date: 2011-10-11 13:06:07
Message-ID: CAFj8pRBDfWZYSbf96QxLapCD3qE1n9hR5px-ZDukhmJUUdmnSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2011/10/11 Boszormenyi Zoltan <zb(at)cybertec(dot)at>:
> Hi,
>
> 2011-10-11 14:23 keltezéssel, Robert Haas írta:
>>
>> 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.
>
> this reminds me that recently I thought about making anyelement
> a real type. anyelement[] would allow you to have different types in
> the same array. The real type OID and the data both would be stored and
> anyelement to cstring would reveal both in e.g.
> 'oid,value_converted_by_outfunc'
> format. The anyelement to real type and any type to anyelement conversion
> would be painless.
>

> The problem is that anyelement (when the underlying type in not text) to
> text
> conversion would be ambiguous and give different answers:
> anyelement -> cstring -> text gives 'oid,value_converted_by_outfunc'
> anyelement -> real type -> cstring -> text gives
> 'value_converted_by_outfunc'
> Stupid idea.
>

it's near a "variant" datatype - Some times I though about some like
"late binding" - but my proposal is significantly simpler, because it
doesn't play with automatic choose of common subtype. It is based on
user choose.

Regards

Pavel

> Best regards,
> Zoltán Böszörményi
>
> --
> ----------------------------------
> Zoltán Böszörményi
> Cybertec Schönig&  Schönig GmbH
> Gröhrmühlgasse 26
> A-2700 Wiener Neustadt, Austria
> Web: http://www.postgresql-support.de
>     http://www.postgresql.at/
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2011-10-11 13:07:22 Re: Proposal: casts row to array and array to row
Previous Message Boszormenyi Zoltan 2011-10-11 12:51:13 Re: Proposal: casts row to array and array to row