Re: Proposal: casts row to array and array to row
От | Pavel Stehule |
---|---|
Тема | Re: Proposal: casts row to array and array to row |
Дата | |
Msg-id | CAFj8pRBDfWZYSbf96QxLapCD3qE1n9hR5px-ZDukhmJUUdmnSA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Proposal: casts row to array and array to row (Boszormenyi Zoltan <zb@cybertec.at>) |
Список | pgsql-hackers |
2011/10/11 Boszormenyi Zoltan <zb@cybertec.at>: > 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. > 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@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-hackers >
В списке pgsql-hackers по дате отправления: