Re: VARIANT / ANYTYPE datatype

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Darren Duncan <darren(at)darrenduncan(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: VARIANT / ANYTYPE datatype
Date: 2011-05-06 20:59:55
Message-ID: 2586.1304715595@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Excerpts from Darren Duncan's message of mi may 04 15:33:33 -0300 2011:
>> I see VARIANT/ANYTYPE as the most general case of supporting union types, which,
>> say, could have more specific examples of "allow any number or date here but
>> nothing else". If VARIANT is supported, unions in general ought to be also.

> Okay, so aside from the performance (storage reduction) gained, there's
> this argument for having variant/union types. It seems to me that this
> is indeed possible to build. Completely general VARIANT, though, is
> rather complex.

Yeah. I have no particular objection to a UNION over a specified set of
types, but am not very happy with the idea of an unconstrained union.

Also, a UNION declaration would allow attaching a field name to each
containable type, as I see Andrew just posted about. That seems like
potentially a good idea.

> In a general variant, the system catalogs do not have the information of
> what type each variant masquerades as. We would need to examine the
> variant's masqueraded types on each insert; if the current type is not
> found, add it. This seems a bit expensive.

Not to mention race-condition-prone. How do you ensure someone is not
inserting another instance of the variant, with some previously not used
content type, while this is going on?

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2011-05-06 21:05:08 Re: VARIANT / ANYTYPE datatype
Previous Message Andrew Dunstan 2011-05-06 20:18:55 Re: VARIANT / ANYTYPE datatype