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

Поиск
Список
Период
Сортировка
От Boszormenyi Zoltan
Тема Re: Proposal: casts row to array and array to row
Дата
Msg-id 4E943BC1.1030606@cybertec.at
обсуждение исходный текст
Ответ на Re: Proposal: casts row to array and array to row  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: Proposal: casts row to array and array to row
Список pgsql-hackers
Hi,

2011-10-11 14:23 keltezéssel, Robert Haas írta:
> On Tue, Oct 11, 2011 at 4:40 AM, Pavel Stehule<pavel.stehule@gmail.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.

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/



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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: Proposal: casts row to array and array to row
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: Proposal: casts row to array and array to row