I've created a variant data type [1]. It seems to work pretty well,
except for some issues with casting.
Since the idea of the type is to allow storing any other data type, it
creates casts to and from all other types. At first these were all
marked as ASSIGNMENT, but that made using variant with functions quite
cumbersome. With functions that accepted a variant, you still had to
explicitly cast it:
SELECT variant_function( some_field::variant.variant ) FROM some_table;
I was reluctant to make the casts to variant IMPLICIT, but it seems like
it actually works rather well... except for arrays:
ERROR: operator is not unique: regtype[] = regtype[]
This was true for all operators, not something unique to regtype[],
presumably because array_cmp() does something slightly different than
the rest of the system. I do have a = operator, but I do not have an
operator class.
For now, I work around this by leaving casts from arrays to variant as
ASSIGNMENT, but I'm wondering if there's a better solution to be had.
I could change my = operator to something else, but I believe that will
break things like IS DISTINCT.
I've wondered if creating an operator class would just fix this, but I'm
not sure. I'd also need a somewhat different comparison function because
right now I don't enforce that there's an operator class to do comparison.
I tried putting the operators into a different schema, but operator
lookup appears to ignore schema.
It's worth noting that the only problem I've seen so far has been
dealing with function calls. It reminds me of the surprise people run
into when they define a function that accepts smallint and then they
can't call it directly. I find myself wondering if there's some way to
handle this at the function call level.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general